Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
please i just recently installed sql server 2008 but i don't know how to integrate it into asp.net(visual studio 2010). previously, i used access database just for small apps, but now i want to develop a commercial website and i will obviously need to upgrade. with access database, to connect all i did is use the connection string and then open the connection before i can proceed to select, update or do any other thing. i.e, i used

OleDbConnection con = new OleDbConnection("Provider=microsoft.JET.OLeDb; Datasource:.\\."

how do i do this with sql server 2008 please.
thank you very much.

chidi
Posted
Comments
[no name] 2-Jul-14 18:26pm    
www.connectionstrings.com

 
Share this answer
 
v2
Please refer this link[^]it will clear your basic under standing of ADO.net
 
Share this answer
 
you can use provider as ".NET Framework Data Provider for SQL Server"
And
Data Source=ServerName\SQL2008;Initial Catalog=databaseName;User ID=sa;Password=****
 
Share this answer
 
Just open your project in visual studio.
Under view click on server Explorer
You can see the Server tool box.
Click on "Connect To Database"
Choose "Microsoft SQL Server (SqlClient)" as Data Source
Choose or enter server name.
Choose login method from windows authentication or username and password.
Select the database name form list
Click on Test Connection
if it is successful then click on ok.
Make right click on added database and click on properties.
Copy that connection string property.
Use this connection string in your web config.
and access it wherever you require.
check this for how to use connection string from web.config
 
Share this answer
 
Comments
Member 10920447 3-Jul-14 4:07am    
thanks everyone, i was able to establish a connection but one more problem please, when i deploy my website, how do i carry the database along. normally with access, i just include it in my project folder but please i need to know whether by adding connection to this sql database, does it automatically include it in your project or do i have to include it in another way?. please help again.

thanks.
Chidi.
Bhushan Mehetre 3-Jul-14 5:33am    
As your questions say's you are doing commercial website. So you have to put your database on live server.
When we purchase hosting for site normally they provide access to create 1 or 2 database server or they have plan for database. so you will choose Microsoft sql server databse hosting for database.
When you get access you have to just replicate the local database to the server.
and change the connection string in web config.
Member 10920447 3-Jul-14 16:43pm    
thanks very much for taking out time to reply, but please just one last question. when i connect via the add connection option from the server explorer, do i still have to change the connection string in the web.config file?
thanks again.
Bhushan Mehetre 7-Jul-14 2:09am    
Yes you have to, in case the server is located on different location.
Sorry For the Late Reply.
The main part in connection string are server location and database name.
server name is like "192.168.2.154\SQLExpress" for the live and for local you will have ".\SQLExpress" or anything else. So as per your desire database destination you have to change web config.
It will same apply for the database name. It is best practice to keep the both name same.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900