Click here to Skip to main content
15,917,862 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi I am having trouble with allowing others to connect to my server. I am running server 2008, I have changed all the settings to allow incoming connections and followed a few guides but all seem to have failed miserable.

This connections string works fine to connect to the db locally:

SqlConnection conn = new SqlConnection("Data Source=.\\SQLExpress;Initial Catalog=Food;Integrated Security=SSPI;");


however when I try and substitute it for a ip based connection string:

SqlConnection conn = new SqlConnection("Data Source= ipaddy,1433;Network Library=DBMSSOCN;Initial Catalog=food;");


it completly crashes my program and it won't load at all.

If someone could help would be much appreciated cheers in advance
Posted
Comments
DanHodgson88 6-Mar-13 9:50am    
Can I ask why everyone has now started answering this? It was a year and a half ago.....

you have 2 error

1) use user name of your pc b4 the servername

error
SQL
Data Source=.\\SQLExpress;Initial 


ans
SQL
Data Source=PC Username\\SQLExpress;Initial


cos (.) only work with Sql 2000

2) use @ b4 connection string



C#
SqlConnection conn = new SqlConnection(@"Data Source=.\\SQLExpress;Initial Catalog=Food;Integrated Security=SSPI;");



And the Final Connection string will

C#
SqlConnection conn = new SqlConnection(@"Data Source=PC Username\\SQLExpress;Initial Catalog=Food;Integrated Security=SSPI;");
 
Share this answer
 
check for the username and password for the server system sql.
 
Share this answer
 
try to store connection string in web.config file..
 
Share this answer
 
you should also give username and password of your database in the string.
 
Share this answer
 
simple way is

drag a datagridview on form
now, see arrow button at top right,
click add new datasource

now in a new window new datasource -> then give name of sql server, username - pwd select database & hit TestConnection button if successful then click ok

in window u will get your connection string copy-paste and use it in code
now u can remove datagridview from form

Happy Coding!
:)
 
Share this answer
 
C#
SqlConnection conn = new SqlConnection(@"Data Source=DATA SERVER ADDRESS ;Initial Catalog='NAME DATA BASE';USE='DATA BASE USER ID';PWD='DATA BSEA PASSWORD'");
 
Share this answer
 
v2
Create a text file (connection.txt) rename it to connection.udl. Open it set and up the connection. Close it and open it again with notepad. The Connection string will be there.
 
Share this answer
 

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