简体   繁体   中英

SqlConnection unable to connect using IP address

pretty simple question.

I cannot connect using this string:

 SqlConnection myConnection = new SqlConnection("network address=(192.168.1.120); password=userpassword; user id=username; database=myDB");

I try to change it to data source, address, anything and anytime I have a period in the string it raises an exception. If I change it to point to my localhost name with no period or a hostname that is not using an FDNQ it works just fine. does anyone know what's up with that?

The exception raised when using an IP address or server name with several subdomains is that the period is invalid. "Incorrect syntax near '.'."

I went to connectionstrings.com and copied the same string I used before and it failed.

Try it like this:

SqlConnection myConnection = new SqlConnection("network address=192.168.1.120; password=userpassword; user id=username; database=myDB");

You can find the comprehensive Keyword reference for SqlConnection connection strings here: http://msdn.microsoft.com/en-us/library/ms130822.aspx

my SQLCommand had bad SQL syntax in it due to several lines of concatenation. Stupid me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM