起先我是这么写的,只指定服务器地址,没有制定sql server 实例名,可以成功链接
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(); sb.DataSource = @"localhost"; sb.InitialCatalog = "Demon"; sb.UserID = "sa"; sb.Password = "sa";
但是指定实例名后就无法链接了,报25的错:
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(); sb.DataSource = @"localhostMSSQLSERVER"; sb.InitialCatalog = "Demon"; sb.UserID = "sa"; sb.Password = "sa";
结果发现是指定实例名的时候必须要制定端口号的,原因不知道,猜测是当没有制定实例名时,微软会默认找,一旦指定实例名,微软便按程序员的连接串链接了。。。。、
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(); sb.DataSource = @"localhostMSSQLSERVER,1433"; sb.InitialCatalog = "Demon"; sb.UserID = "sa"; sb.Password = "sa";
不指定实例名,只指定端口号都是可以的。。。
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(); sb.DataSource = @"localhostMSSQLSERVER,1433"; sb.InitialCatalog = "Demon"; sb.UserID = "sa"; sb.Password = "sa";