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 中。其他信息: 系统错误。
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 中。其他信息: 系统错误。
server=localhost;database=northwind;uid=sa;pwd="";
connStr = "Data Source=localhost;Server=MS-08E134396982;database=NorthWind;uid=sa;pwd=;" ;在一台机器上行,在另外一台机器上就不行(我已经改了Server=MS-08E134396982的内容)
connectionstring, 把这个字符串的内容拷贝过来给connStr,删掉sqlconnection 就可以了
connStr = "Data Source=localhost;Server=MS-08E134396982;database=NorthWind;uid=sa;pwd=;" ;在一台机器上行,在另外一台机器上就不行(我已经改了Server=MS-08E134396982的内容)
connStr="data source=localhost;initial catalog=northwind;uid=sa;pwd="