在VS2017连接SQLserver数据库后运行的报错,远程连接已设置,数据库实例确定没有问题
报错显示如下:
System.Data.SqlClient.SqlException:“在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - 无法打开到 SQL Server 的连接)”
报错程序段:
public partial class Form1 : Form
{
public static string thisConnectString = @"Data Source=.; Database = 仓储管理系统数据库; Integrated Security=true";
public Form1()
{
InitializeComponent();
}
//登陆
private void button2_Click(object sender, EventArgs e)
{
SqlConnection thisConnect = new SqlConnection(thisConnectString);
SqlCommand cmd = new SqlCommand("login_proc", thisConnect);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@user", textBox1.Text);
cmd.Parameters.AddWithValue("@pws", textBox2.Text);
SqlParameter par = cmd.Parameters.Add("@status", SqlDbType.Int); //定义输出参数
par.Direction = ParameterDirection.Output; //参数类型为Output
thisConnect.Open();
cmd.ExecuteNonQuery();
报错是thisConnect.Open();这一句
尝试过网上说的把 Integrated Security=true改成User ID= ;pwd= ; 但是问题没有解决