Saturday, February 25, 2012

Connecting SQL server to the net?

Hi all. Im using Visual Web developer 2005 and have successfully connected my SQL Server to Visual Web developer website. When i run it locally, its fine. But, i now would like the site to be placed on the net - but im not sure how to connect it properly in the webhost. Can someone tell me how this is done please, or a link? cheers.

You can add a connection string on web.config file

<connectionStrings>

<add name="connectioname" connectionString="server=database server;uid=username; pwd=pasword; database=databasename;"/>

</connectionStrings>

then call this connection string on your page.

string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["connectionname"].ConnectionString;

I hope this will help.

|||

Ok.....im still rather confused on how exactly the databse is linked. Firstly, i have the site on a external harddrive....but ive found that the SQL server databse is placed in a totally different location - C:\Program Files (x86)\Microsoft SQL Server\MSSQL.2\MSSQL\Data\Database.mdf

Surely i would have to link it some how for the site/databse to work properly on the site?

|||No ideas guys? Surely there must be a way so i can upload my SQL server database and connect it to my website? I can do it easily in Visual Web Developer in my computer....but stummped how to do it on the net.....|||

Hi,

You may follow the steps below.

First, backup you local database.

Second, get the physical folder of the database file exist on your server. From your previous post, it isC:\Program Files (x86)\Microsoft SQL Server\MSSQL.2\MSSQL\Data\.

Third, restore your backup file to your server database. (Note, you have to replace theMove to Physical file nameitem in the Option tab with your real server-side database folder.)

Third, modify the connection string in your web.config file and call the string in your code by ConfigurationManager.

Thanks.

No comments:

Post a Comment