请问一个C#应用程序想连接2个不同服务器的SQL代码应该怎样写啊?我写了下面代码,但是提示SA为NULL登陆失败,不知道为什么。
SqlConnection myConn;
myConn = new SqlConnection("server=;database=;user=sa;password=;Trusted_Connection=SSPI;");
String selectCmd = "select * from user where user='" + this.textBox1.Text.Trim() + "'";
...全文
1017打赏收藏
请问一个C#应用程序想连接2个不同服务器的SQL代码应该怎样写啊?
请问一个C#应用程序想连接2个不同服务器的SQL代码应该怎样写啊?我写了下面代码,但是提示SA为NULL登陆失败,不知道为什么。 SqlConnection myConn; myConn = new SqlConnection("server=;database=;user=sa;password=;Trusted_Connection=SSPI;"); String selectCmd = "select * from user where user='" + this.textBox1.Te
"SqlConnection myConn;
myConn = new SqlConnection("server=;database=;user=sa;password=;Trusted_Connection=SSPI;");
String selectCmd = "select * from user where user='" + this.textBox1.Text.Trim() + "'";
"
既然Integrated security设置为SSPI了,就说明是使用windows身份验证;
干嘛还要指定sa和密码?
还有就是还要看你的sql 服务器的验证方式,是windows身份验证还是混合验证;一般推荐是混合身份验证(毕竟客户端和服务器不再同一台主机的可能性极大)
myConn = new SqlConnection("server=server的ip地址;database=数据库名;Integrated security=SSPI;");
或者
myConn = new SqlConnection("server=server的ip地址;database=数据库名;user=sa;password=;"); (sa的密码为空)
连接两个不同的服务器,把连接源更改
myConn1 = new SqlConnection("server=;database=aa;user=sa;password=;Trusted_Connection=SSPI;");
myConn2 = new SqlConnection("server=;database=xx;user=sa;password=;Trusted_Connection=SSPI;");
我写了下面代码,但是提示SA为NULL登陆失败,不知道为什么。
SqlConnection myConn;
myConn = new SqlConnection("server=;database=;user=sa;password=;Trusted_Connection=SSPI;");
String selectCmd = "select * from user where user='" + this.textBox1.Text.Trim() + "'";
改成下面代码,又提示用户登陆失败·!
myConn = new SqlConnection("data source=;uid=sa;password=;database=;Max Pool Size=50; Min Pool Size=5 ;");