-3

I tried to create SqlConnection object with connection string such as

SqlConnection con = new SqlConnection("Connection string");

However, when the program runs, exception happens, and the exception says

the keyword, port, is not supported.

So I change connection string from

server=server name;user id= user name;password=myPassword;persistsecurityinfo=False;database=Database name;Port=port number

to

server=server_name, portNum;user id= user_name;password=myPassword;persistsecurityinfo=False;database=Database_name;

or to

server=server_name: portNum;user id= user_name;password=myPassword;persistsecurityinfo=False;database=Database_name;

But I still have problems to connect to database.

Could anyone give me how to connect database with port number?

Sincerely,

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user3839421
  • 1
  • 1
  • 1
  • 4
    Check out [connectionstrings.com](http://connectionstrings.com) which has **tons** of samples of how to build your connection string. Or use the `SqlConnectionStringBuilder` class ([documented on MSDN](http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder%28v=vs.110%29.aspx) ) to handle this for you – marc_s Jul 15 '14 at 05:32
  • what problems are you having after removing the port? – lockstock Jul 15 '14 at 06:06
  • Did you try without the space between `server_name, portNum`? – Marc Gravell Jul 15 '14 at 07:16

1 Answers1

1

You can use the port at the end of the data source

Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

Check http://www.connectionstrings.com/sql-server/

Shubham Bhave
  • 383
  • 6
  • 17