string one = "Data Source=wuchao159753-pc;Initial Catalog=UesrYan;Integrated Security=True";
SqlConnection connection=new SqlConnection(one);
int num;
string message="";
string sql = "SELECT COUNT(*) FROM UesrYan "; try
{
connection.Open();
SqlCommand command = new SqlCommand(sql,connection);
num = (int)command.ExecuteScalar();
message = string.Format("UesrYan表中共有(0)个用户",num);
MessageBox.Show(message,"查询结果",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
}catch(Exception ex){
MessageBox.Show(ex.Message);
}finally{
connection.Close();
MessageBox.Show("关闭数据库成功");在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - 无法打开到 SQL Server 的连接)
请各位大侠帮忙解析
SqlConnection connection=new SqlConnection(one);
int num;
string message="";
string sql = "SELECT COUNT(*) FROM UesrYan "; try
{
connection.Open();
SqlCommand command = new SqlCommand(sql,connection);
num = (int)command.ExecuteScalar();
message = string.Format("UesrYan表中共有(0)个用户",num);
MessageBox.Show(message,"查询结果",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
}catch(Exception ex){
MessageBox.Show(ex.Message);
}finally{
connection.Close();
MessageBox.Show("关闭数据库成功");在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - 无法打开到 SQL Server 的连接)
请各位大侠帮忙解析
进入配置管理器,开命远程访问下的命名管道和TCP
如果上面两项都没有问题,再看看连接字符串,检查杀软或防火墙是否有屏蔽SQL远程端口