简体   繁体   English

SQL Server EXPRESS:错误:26-在安装后指定服务器/实例时出错

[英]SQL Server EXPRESS: Error: 26 - Error Locating Server/Instance Specified after setup

(C#/ .Net Framework4.0 / VS2017). (C#/ .Net Framework4.0 / VS2017)。 made ac# windows form with sqlcon expressconnection database,but rly not sure how to create a setup for other client... 用sqlcon expressconnection数据库制作了ac#windows表单,但是还不确定如何为其他客户端创建安装程序...

i have made a windows form application with a database with sqlconnection in it. 我做了一个Windows窗体应用程序,其中带有sqlconnection的数据库。 im using advance installer to create a setup so i can put the .mdf and .idf files with prerequsites easily. 即时通讯使用高级安装程序来创建安装程序,因此我可以轻松地将.mdf和.idf文件放在先决条件下。

added connection string as: 添加的连接字符串为:

 public static class DAL
    {
        public static DataTable ExecSP(string spName, List<SqlParameter> sqlParams = null)
        {
            string strConnect = "Server=PC\\SQLEXPRESS;Database=MyLoginApp;Trusted_Connection=True;";     
            SqlConnection conn = new SqlConnection();
            DataTable dt = new DataTable();

        try
        {
            //Connect to the database
            conn = new SqlConnection(strConnect);
            conn.Open();

            //Build an sql command / query
            SqlCommand cmd = new SqlCommand(spName, conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddRange(sqlParams.ToArray());

            //Execute command
            SqlCommand command = conn.CreateCommand();
            SqlDataReader dr = cmd.ExecuteReader();

            //fill datatable with the results
            dt.Load(dr);


        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            //No matter what happends this will run
            conn.Close();
        }
        return dt;
    }
}

When it trying to execute the following code: 当它尝试执行以下代码时:

private void btnLogin_Click(object sender, EventArgs e)
    {
        List<SqlParameter> sqlParams = new List<SqlParameter>();
        sqlParams.Add(new SqlParameter("Username", TxtUsername.Text));
        sqlParams.Add(new SqlParameter("Password", txtPassword.Text));

        DataTable dtLoginResults = DAL.ExecSP("ValidateLogin", sqlParams);

        string eUser;
        string ePass;
        eUser = TxtUsername.Text;
        ePass = txtPassword.Text;


        if (dtLoginResults.Rows.Count == 1)
        {
            //We know login is valid
            string user = dtLoginResults.Rows[0]["Username"].ToString();
            MessageBox.Show(user + " Berhasil Masuk!");
            this.Hide();
            ListMeja lm = new ListMeja();
            lm.ShowDialog();
        }     
         else
        {
            //invalid login
            MessageBox.Show("Password Salah");
        }    
    } 

gets an error popup window in other client after run the .exe program 运行.exe程序后在其他客户端中获取错误弹出窗口

Unhandled exception has occured in your application. 您的应用程序中发生了未处理的异常。 if you click Continue, the application will ignore this error and and attempt to continue. 如果单击“继续”,则应用程序将忽略此错误并尝试继续。 A network -related or instance-specific error occured while establish a connection to SQL server.The server was not accessible. 建立与SQL Server的连接时发生与网络相关或特定于实例的错误。该服务器不可访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified). (提供者:SQL网络接口,错误:26-查找指定的服务器/实例时出错)。

what im doing wrong here ? 我在这里做错了什么?

well.. this is the solution 好..这是解决方案

SqlConnection con = new SqlConnection(@"Data Source = .\SQLEXPRESS;" +
         @"AttachDbFilename=|DataDirectory|\MyLoginApp.mdf;Integrated Security = True;User Instance=True");
            private void Form1_Load(object sender, EventArgs e)

Please try to Connect SQL Server With SSMS from Your system. 请尝试从您的系统将SQL Server与SSMS连接。 After Successfully Login Please Edit your string strConnect = "Server=PC\\\\SQLEXPRESS;Database=MyLoginApp;Trusted_Connection=True;"; 成功登录后,请编辑您的string strConnect = "Server=PC\\\\SQLEXPRESS;Database=MyLoginApp;Trusted_Connection=True;"; connection string as per SSMS Connected. 根据SSMS已连接的连接字符串。

暂无
暂无

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

相关问题 使用C#的SQL上的错误26,指定了错误定位服务器/实例 - Error 26 on SQL with C#, error locating server / instance specified SQL错误:26-查找指定的服务器/实例时出错 - SQL error:26 - Error Locating Server/Instance Specified 脚手架后的迁移问题。 (提供者:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例) - Migration issue after scafolding. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) SQL服务器错误(提供程序:SQL网络接口,错误:26-错误指定服务器/实例的位置) - SQL SERVER ERROR (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) ASP.Net错误26错误定位指定的服务器/实例 - ASP.Net Error 26 Error Locating Server/Instance Specified 错误 26 - 定位服务器/指定实例时出错 - error 26- error locating server/instance specified 错误26的解决方案-指定错误的服务器/实例定位? - Solution for Error 26 - Error Locating Server/Instance Specified? 错误26:错误定位生产环境中指定的服务器/实例-SQL Server 2014 WPF WCF - Error 26: Error Locating Server/Instance Specified in production environment - SQL server 2014 wpf wcf 仅在调试时才出现SQL Server错误26(指定错误的服务器/实例) - SQL Server Error 26 (Error Locating Server/Instance Specified) Only When Debugging SQL Server Compact Edition 4.0:错误:26 - 找到指定的服务器/实例时出错 - SQL Server Compact Edition 4.0: Error: 26 - Error Locating Server/Instance Specified
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM