string lianjie = "Data Source=PC-10191758 Initial Catalog=vote Integrated Security=false";
public vote()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public SqlDataReader getvotes()
{
SqlConnection con = new SqlConnection(lianjie);
SqlCommand com = new SqlCommand("pr_getvotes", con);
com.CommandType = CommandType.StoredProcedure;
SqlDataReader da = null;
try
{
con.Open();
da = com.ExecuteReader();
return da;
}
/* catch (Exception ex)
{
}*/
finally
{
con.Close();
}
}
在红色部分老是出问题:在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)
========
既然你已经设置Integrated Security=false了
那么User ID= ?? ;Password=???或者你这样写:
string lianjie = "Data Source=PC-10191758 Initial Catalog=vote Integrated Security=true";
这是什么道理?
这是你的连接数据库的字符串吗?这样肯定连不上。字符串里面少;了。字符串怎么写3楼已经给你写好了。
然后又没登录名跟密码,还有连接字符串要;隔开