繁体   English   中英

如何解决 System.Data.SqlClient.SqlException:

[英]How to solve System.Data.SqlClient.SqlException:

每当我运行我的代码时,我都会收到此错误:

与 SQL Server 建立连接时发生与网络相关或特定于实例的错误。 服务器未找到或无法访问。 验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供程序:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)

我尝试使用互联网上提供的解决方案,但似乎没有任何效果。 就像使用 Windows 服务的那个一样,我在本地服务列表中找不到"SQL SERVER (NAME)"

SqlConnection connect = new SqlConnection (@"Data Source = DESKTOP-766P0MJ; Initial Catalog = LoginCredentials; Integrated Security = True");
SqlDataAdapter adapt = new SqlDataAdapter("SELECT COUNT(*) FROM LoginCredentials where username = '" + txtbox_username.Text + "' AND password = '" + txtbox_password.Text + "'", connect);

DataTable dt = new DataTable(); //this is creating a virtual table  
adapt.Fill(dt);

if (dt.Rows[0][0].ToString() == "1")
{
    /* I have made a new page called home page. If the user is successfully authenticated then the form will be moved to the next form */
    this.Hide();
    new InternRequest().Show();
}
else
    MessageBox.Show("Invalid username or password");

如果您的 sql server 服务已启动并且您再次出现此错误,则启动另一个名称为SQL Server Browser sql server 服务,当您在服务器名称中运行 sql server management studio 时,您可以选择Browse for more并在数据库引擎中显示您的实例sql server的名称点击它并连接它并检查您的用户名和密码以进行连接。

打开运行并键入 services.msc。 服务窗口将打开。 在该窗口中找到 MSSQLSERVER 及其相关文件。 启动它,或者如果它已启动,您可以重新启动它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM