日期:2014-05-18  浏览次数:20815 次

C#连接SQL2000错误!恳请大家帮个忙解决下啊!!!!
环境:WIN VISTA 工具:VS2005 SQL2005 SQL2000(先安装的是2005).

错误描述:
  在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 

企业管理器里面是:
Microsoft SQL Severs
  SQL Server 组
  ABC-wx\PSP(Windows NT) IP:192.168.27.49

详细连接代码:
  SqlConnection connection = new SqlConnection("server=192.168.27.49;database=Contorl;uid=cqaf55648;pwd=aptx4869;");
  connection.Open();
  SqlCommand command = new SqlCommand("select count(*) as total from sysobjects where name='" + this.textBox1.Text + "'", connection);
  if (Convert.ToInt32(command.ExecuteScalar()) == 1)
  {
  //MessageBox.Show("已存在!!");
  connection.Close();
  this.Close();
  }



红色为错误处!!

请大家帮个忙啊,谢谢啦.....

------解决方案--------------------
连接字符串可以这样写:server=ABC-wx\\PSP;database=Contorl;uid=cqaf55648;pwd=aptx4869; 

注意是两个"\",在C#中要使用特殊符号需要用到转接符"\",或者你可以把SQL2005的服务先停掉,只剩下SQL2000的服务就好.

------解决方案--------------------
单 \ 变成双 \\
字符串就是这样用的