gpt4 book ai didi

c# - 应用程序中的服务器错误 '/demo'

转载 作者:行者123 更新时间:2023-11-30 00:07:28 25 4
gpt4 key购买 nike

错误如下:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Source Error:

Line 69: public Boolean UserAuthentication(string UserID, string Password)

Line 70: {

Line 71: Con.Open(); // Red Color - showing this is the error.

Line 72:

Line 73: SqlCommand cmd = new SqlCommand("SELECT * FROM LoginList WHERE UserID = '" + UserID + "' AND Password = '" + Password + "'", Con);

我的连接字符串编写如下:

static SqlConnection Con = new SqlConnection(
@"Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\Database.mdf;
Integrated Security=True;
User Instance=True");

注意:防火墙服务已禁用,SQL 服务器名称没有错误。

最佳答案

尝试这样,

static SqlConnection Con = new SqlConnection(
@"Data Source=.\SQLEXPRESS;
Initial Catalog=Database.mdf;
Integrated Security=True;
User Instance=True");

关于c# - 应用程序中的服务器错误 '/demo',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24400319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com