Connection Strings

Last post 06-22-2007 11:44 PM by chrixian. 6 replies.

Sort Posts:

  • Indifferent [:|] Connection Strings

    06-22-2007, 4:10 AM
    • Loading...
    • zakman411
    • Joined on 06-22-2007, 1:23 AM
    • California
    • Posts 52

    New to ASP. When I run my site from local machine, it works great, i can create users etc, however, when i deploy the page online, cant create users. I think it is because the web.config file isnt linking to the database. I dont think I have the correct connectioin strings in it.I put:

    <connectionStrings>
        <add name="ClubSiteDB" connectionString="Data Source=.\SQLExpress;Integrated Security=true;AttachDBFileName=|DataDirectory|ASPNETDB.mdf;User Instance=True" providerName="System.Data.SqlClient"/>
      </connectionStrings>

     And it still doesnt work. I dont understant what the <add name> tag does, so that may be the problem. What exactly does the <add name> tag do, and do I even have the correct script? Thanks in advance.
     

    -Zach Spitulski-
  • Re: Connection Strings

    06-22-2007, 5:17 AM
    • Loading...
    • chrixian
    • Joined on 06-20-2007, 10:54 PM
    • Fort Worth, Tx
    • Posts 13

    zakman411:

    New to ASP. When I run my site from local machine, it works great, i can create users etc, however, when i deploy the page online, cant create users. I think it is because the web.config file isnt linking to the database. I dont think I have the correct connectioin strings in it.I put:

    <connectionStrings>
        <add name="ClubSiteDB" connectionString="Data Source=.\SQLExpress;Integrated Security=true;AttachDBFileName=|DataDirectory|ASPNETDB.mdf;User Instance=True" providerName="System.Data.SqlClient"/>
      </connectionStrings>

     And it still doesnt work. I dont understant what the <add name> tag does, so that may be the problem. What exactly does the <add name> tag do, and do I even have the correct script? Thanks in advance.

     The <connectionStrings> element is a collection of connection strings as name/value pairs. It's child element <add> has 2 attributes "name" and "connectionString". In your example you have a connection named "ClubSiteDB" and the connection is to an instance of SQL Server 2005 Express running on your local machine called .\SQLExpress. This is why it works on your local machine but not from your host: the Data Source ".\SQLExpress" is running on your local machine, when the remote host trys to connect to ".\SQLExpress" it doesn't know what that is. You will need to find out if your host provides you with a database and you'll have to create the database ClubSiteDB on that remote database server and provide a valid connection string in your web.config to connect to that database.

     

    Hope this helps!
     

  • Re: Connection Strings

    06-22-2007, 8:12 AM
    • Loading...
    • Nitinkcv
    • Joined on 03-13-2007, 11:07 AM
    • Posts 264

     Hi,

     I suggest you go through this site. http://connectionstrings.com/ 

    Thanks
  • Re: Connection Strings

    06-22-2007, 1:46 PM
    • Loading...
    • zakman411
    • Joined on 06-22-2007, 1:23 AM
    • California
    • Posts 52

    Ok, I kind of understand now, i just dont know how to get the connection strings. I created a database on my host (godaddy), and it came up with the database name (DB_1014172) with a host name of p3swhsql.shr.phx.secureserver.net.  Plus I know my username and password. But how am I supposed to put all of that info into this:

    Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;

    (if thats even the right code :|  )

    Can someone please help me figure this out? I just need to know what I should put for each tag (Driver=, Server=, AttachDBFilename etc)

     Thanks in Advance..Im new at this
     

    -Zach Spitulski-
  • Re: Connection Strings

    06-22-2007, 2:28 PM
    Answer
    • Loading...
    • chrixian
    • Joined on 06-20-2007, 10:54 PM
    • Fort Worth, Tx
    • Posts 13

    zakman411:

    Ok, I kind of understand now, i just dont know how to get the connection strings. I created a database on my host (godaddy), and it came up with the database name (DB_1014172) with a host name of p3swhsql.shr.phx.secureserver.net.  Plus I know my username and password. But how am I supposed to put all of that info into this:

    Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;

    (if thats even the right code :|  )

    Can someone please help me figure this out? I just need to know what I should put for each tag (Driver=, Server=, AttachDBFilename etc)

     Thanks in Advance..Im new at this



    Ohhh ok I think we're finally on the same page... your web.config will look like this:

    <connectionStrings>
        <add name="ClubSiteDB"
                connectionString="Server=p3swhsql.shr.phx.secureserver.net; Database=DB_1014172; User ID=user_id;Password=password; Trusted_Connection=False" providerName="System.Data.SqlClient" />
    </connectionStrings>

     

     

  • Re: Connection Strings

    06-22-2007, 11:23 PM
    • Loading...
    • zakman411
    • Joined on 06-22-2007, 1:23 AM
    • California
    • Posts 52

     I understand all of that except for the <add name "ClubSiteDB"> tag. What exactly is that? I'm guessing its the name of the database, but my database isnt named that.

    <br>

    Should I replace the <add name "ClubSiteDB"> tag with the name of my database that is actually in asp.net? If I do that, im guessing i will need to copy and paste the contents of the database from asp.net to the database on the server, or am I wrong? Thanks for the help so far. 

    -Zach Spitulski-
  • Re: Connection Strings

    06-22-2007, 11:44 PM
    • Loading...
    • chrixian
    • Joined on 06-20-2007, 10:54 PM
    • Fort Worth, Tx
    • Posts 13

    zakman411:

    I understand all of that except for the <add name "ClubSiteDB"> tag. What exactly is that? I'm guessing its the name of the database, but my database isnt named that.

    Should I replace the <add name "ClubSiteDB"> tag with the name of my database that is actually in asp.net? If I do that, im guessing i will need to copy and paste the contents of the database from asp.net to the database on the server, or am I wrong? Thanks for the help so far.
     

    No, the name that is set in the <add> element is simply a unique name you will use to refer to that connection string to that database, you can name it whatever you like. By defining that in your web.config when you use a built-in DataSource control in the design view you'll actually be able to select that name from a drop down list for the database connection or access it programatically as ConnectionStrings.ClubSiteDB (or whatever you put in that "name" field)

Page 1 of 1 (7 items)
Microsoft Communities
Page view counter