"Unable to connect to SQL Server database" error when using profile

Discussion in 'ASP .Net' started by Peter Afonin, Oct 8, 2006.

  1. Peter Afonin

    Peter Afonin Guest

    Hello,

    I'm using CreateUserWizard control in ASP.NET 2.0. I'm storing the data in
    SQL Server 2005.

    The first and last steps run smoothly without any problems. But I added one
    middle step to collect some other information from the user. I've added this
    to Web.config:

    <profile>
    <properties>
    <add name="FirstName" />
    <add name="LastName" />
    <add name="Country" />
    <add name="City" />
    <add name="Email2" />
    </properties>
    </profile>

    Then I try to collect this data:

    Protected Sub cuzGudzon_FinishButtonClick(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.WizardNavigationEventArgs) Handles
    cuzGudzon.FinishButtonClick
    Try
    With Profile
    ..FirstName = Me.txtFirstName.Text
    ..LastName = Me.txtLastName.Text
    ..Country = Me.txtCountry.Text
    ..City = Me.txtCity.Text
    ..Email2 = Me.txtEmail2.Text
    End With
    Catch ex As Exception
    Me.lblError.Text = ex.Message
    Finally
    End Try
    End Sub

    This is where I get an error: Unable to connect to SQL Server database

    Aparently, the connection string I specified in Web.config is correct, since
    the first step where the user creates a user name and password runs without
    any problems, and the data is entered into the database. Am I missing
    something in this additional step?

    I would appreciate your help.

    Thank you,

    --
    Peter Afonin
     
    Peter Afonin, Oct 8, 2006
    #1
    1. Advertising

  2. Make sure you have set up the Profile to use the proper connection string.
    Membership and Profile are two completely separate sections in the
    web.config. Same is true for Roles. While this may seem counter intuitive,
    the reason for this is flexibility, as you might want to include the default
    membership, but custom profile and role providers. You can do this with a
    simple config change (and code to support the custom elements, of course).

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA
    http://gregorybeamer.spaces.live.com/

    *************************************************
    Think Outside the Box!
    *************************************************
    "Peter Afonin" <> wrote in message
    news:...
    > Hello,
    >
    > I'm using CreateUserWizard control in ASP.NET 2.0. I'm storing the data in
    > SQL Server 2005.
    >
    > The first and last steps run smoothly without any problems. But I added
    > one middle step to collect some other information from the user. I've
    > added this to Web.config:
    >
    > <profile>
    > <properties>
    > <add name="FirstName" />
    > <add name="LastName" />
    > <add name="Country" />
    > <add name="City" />
    > <add name="Email2" />
    > </properties>
    > </profile>
    >
    > Then I try to collect this data:
    >
    > Protected Sub cuzGudzon_FinishButtonClick(ByVal sender As Object, ByVal e
    > As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles
    > cuzGudzon.FinishButtonClick
    > Try
    > With Profile
    > .FirstName = Me.txtFirstName.Text
    > .LastName = Me.txtLastName.Text
    > .Country = Me.txtCountry.Text
    > .City = Me.txtCity.Text
    > .Email2 = Me.txtEmail2.Text
    > End With
    > Catch ex As Exception
    > Me.lblError.Text = ex.Message
    > Finally
    > End Try
    > End Sub
    >
    > This is where I get an error: Unable to connect to SQL Server database
    >
    > Aparently, the connection string I specified in Web.config is correct,
    > since the first step where the user creates a user name and password runs
    > without any problems, and the data is entered into the database. Am I
    > missing something in this additional step?
    >
    > I would appreciate your help.
    >
    > Thank you,
    >
    > --
    > Peter Afonin
    >
     
    Cowboy \(Gregory A. Beamer\), Oct 8, 2006
    #2
    1. Advertising

  3. Peter Afonin

    Peter Afonin Guest

    Thank you, Gregory,

    This was a main problem - I couldn't find any example on how to do this.
    Finally figured this out:

    <profile defaultProvider="GudzonProfileProvider">
    <providers>
    <add name="GudzonProfileProvider"
    type="System.Web.Profile.SqlProfileProvider" connectionStringName="Gudzon"/>
    </providers>
    <properties>
    <add name="FirstName" />
    <add name="LastName" />
    <add name="Country" />
    <add name="City" />
    <add name="Email2" />
    </properties>
    </profile>

    Peter



    "Cowboy (Gregory A. Beamer)" <> wrote in
    message news:%...
    > Make sure you have set up the Profile to use the proper connection string.
    > Membership and Profile are two completely separate sections in the
    > web.config. Same is true for Roles. While this may seem counter intuitive,
    > the reason for this is flexibility, as you might want to include the
    > default membership, but custom profile and role providers. You can do this
    > with a simple config change (and code to support the custom elements, of
    > course).
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    > http://gregorybeamer.spaces.live.com/
    >
    > *************************************************
    > Think Outside the Box!
    > *************************************************
    > "Peter Afonin" <> wrote in message
    > news:...
    >> Hello,
    >>
    >> I'm using CreateUserWizard control in ASP.NET 2.0. I'm storing the data
    >> in SQL Server 2005.
    >>
    >> The first and last steps run smoothly without any problems. But I added
    >> one middle step to collect some other information from the user. I've
    >> added this to Web.config:
    >>
    >> <profile>
    >> <properties>
    >> <add name="FirstName" />
    >> <add name="LastName" />
    >> <add name="Country" />
    >> <add name="City" />
    >> <add name="Email2" />
    >> </properties>
    >> </profile>
    >>
    >> Then I try to collect this data:
    >>
    >> Protected Sub cuzGudzon_FinishButtonClick(ByVal sender As Object, ByVal e
    >> As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles
    >> cuzGudzon.FinishButtonClick
    >> Try
    >> With Profile
    >> .FirstName = Me.txtFirstName.Text
    >> .LastName = Me.txtLastName.Text
    >> .Country = Me.txtCountry.Text
    >> .City = Me.txtCity.Text
    >> .Email2 = Me.txtEmail2.Text
    >> End With
    >> Catch ex As Exception
    >> Me.lblError.Text = ex.Message
    >> Finally
    >> End Try
    >> End Sub
    >>
    >> This is where I get an error: Unable to connect to SQL Server database
    >>
    >> Aparently, the connection string I specified in Web.config is correct,
    >> since the first step where the user creates a user name and password runs
    >> without any problems, and the data is entered into the database. Am I
    >> missing something in this additional step?
    >>
    >> I would appreciate your help.
    >>
    >> Thank you,
    >>
    >> --
    >> Peter Afonin
    >>

    >
    >
     
    Peter Afonin, Oct 8, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brad
    Replies:
    1
    Views:
    1,180
    Roedy Green
    Jul 19, 2005
  2. Andy B
    Replies:
    0
    Views:
    558
    Andy B
    May 3, 2008
  3. James

    Unable to connect to SQL Server database

    James, Oct 4, 2006, in forum: ASP .Net Security
    Replies:
    3
    Views:
    569
    James
    Oct 6, 2006
  4. ZZ_Scarab
    Replies:
    2
    Views:
    2,525
    ravish
    Jan 5, 2011
  5. James
    Replies:
    2
    Views:
    479
    James
    Oct 4, 2006
Loading...

Share This Page