今天用vs.net2005连接sql2000时出现了错误。。
在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会
导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连
接)
我知道我的vs里自来个sql2005express版本。我要连接sql2000不是2005啊。。
怎么才能连接到2000呢。要打sp4补丁吗?郁闷中。。。代码如下:
using
System;
using System.Data;
using System.Data.SqlClient;
class Sample
{
public static void Main()
{
SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
SqlCommand catCMD = nwindConn.CreateCommand();
catCMD.CommandText = "SELECT CategoryID, CategoryName FROM Categories";
nwindConn.Open();
SqlDataReader myReader = catCMD.ExecuteReader();
while (myReader.Read())
{
Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
}
myReader.Close();
nwindConn.Close();
}
}
using System.Data;
using System.Data.SqlClient;
class Sample
{
public static void Main()
{
SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
SqlCommand catCMD = nwindConn.CreateCommand();
catCMD.CommandText = "SELECT CategoryID, CategoryName FROM Categories";
nwindConn.Open();
SqlDataReader myReader = catCMD.ExecuteReader();
while (myReader.Read())
{
Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
}
myReader.Close();
nwindConn.Close();
}
}
代码很简单。。可就是连接不上。。
PS:问题解决了,原来是实例的问题,哈哈。。
连接字符串server后面加上.\\sql2000的实例名
就OK了。。
在这里感谢晓月无铭