string connStr, selectCmd;
connStr = "Data Source=localhost;Server=MS-08E134396982;database=NorthWind;uid=sa;pwd=;" ;
selectCmd = "SELECT * FROM Products"; string a="a"; 
SqlConnection conn;
SqlCommand cmd;
SqlDataReader reader;
conn = new SqlConnection(connStr);
conn.Open();
cmd = new SqlCommand(selectCmd, conn);//提示这里有错误
reader = cmd.ExecuteReader();
for(int i=0; i<reader.FieldCount; i++)
{
a += reader.GetName(i) + "\t";
}
a += "\n\n";
while(reader.Read())
{
for (int j=0; j<reader.FieldCount; j++)
{
a += reader[j] + "\t";
}
a += "\n";
}
System.Console.WriteLine(a);
reader.Close();
显示错误信息
未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。其他信息: 系统错误。

解决方案 »

  1.   

    connStr = "Data Source=localhost;Server=MS-08E134396982;database=NorthWind;uid=sa;pwd=;" ;一般好象是这么写的
    server=localhost;database=northwind;uid=sa;pwd="";
      

  2.   

    见鬼了
    connStr = "Data Source=localhost;Server=MS-08E134396982;database=NorthWind;uid=sa;pwd=;" ;在一台机器上行,在另外一台机器上就不行(我已经改了Server=MS-08E134396982的内容)
      

  3.   

    connStr格式不对, 先放一个sqlconnection 控件,连接到合适的数据库上面,然后看看系统自动生成的
    connectionstring, 把这个字符串的内容拷贝过来给connStr,删掉sqlconnection 就可以了
      

  4.   

    见鬼了
    connStr = "Data Source=localhost;Server=MS-08E134396982;database=NorthWind;uid=sa;pwd=;" ;在一台机器上行,在另外一台机器上就不行(我已经改了Server=MS-08E134396982的内容)
      

  5.   

    connStr = "Data Source=localhost;Server=MS-08E134396982;database=NorthWind;uid=sa;pwd=;" ;两台机器数据库的密码一样吗?另外,有些机器不能解析localhost,需要用127.0.0.1
      

  6.   

    好像连接字符串的问题。
    connStr="data source=localhost;initial catalog=northwind;uid=sa;pwd="