简体   繁体   English

SQL错误:26-查找指定的服务器/实例时出错

[英]SQL error:26 - Error Locating Server/Instance Specified

I am attempting to run a program that gets data from a remote sql server, it works for a coworker from another remote site but when I run the program the debugger says that Sql_Reader is returning null. 我试图运行一个从远程sql服务器获取数据的程序,该程序适用于另一个远程站点的同事,但是当我运行该程序时,调试器说Sql_Reader返回null。

I can ping and connect to the remote sql server. 我可以ping并连接到远程sql服务器。 The instance is correct as well as the firewall settings on the server per http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx However when I run a program to get data from the sql server there is and error that says that remote server was not found or not accessible. 根据http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating- server-instance-specified.aspx但是,当我运行程序以从sql服务器获取数据时,出现错误并指出找不到或无法访问远程服务器。

I checked the connection string per error: 26 - Error Locating Server/Instance Specified. 我检查了每个错误的连接字符串:26-指定服务器/实例时出错。 (Can't connect to my local Db From my host server) (无法从主机服务器连接到本地Db)

This is the connection string that is in the GetConnectionString method. 这是GetConnectionString方法中的连接字符串。

    return @"Data Source= 2.2.2.2\SQLEXPRESS; Persist Security Info=False;User ID=myusername;Password=mypassword;Initial Catalog=SomeDataStructure;";

The following error happens on the line that has sql_Connection.Open(); 在具有sql_Connection.Open()的行上发生以下错误:

SqlException was Unhandled. SqlException未处理。 A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与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. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (提供者:SQL网络接口,错误:26-指定服务器/实例时出错)

    // Body of the method
    str_Query = "SELECT " + dict_SearchData["FieldName"] + " FROM " + dict_SearchData["Table"] +
            " WHERE " + dict_SearchData["IndexColumn"] + " = '" + dict_SearchData["IndexRow"] + "';";
        using (SqlConnection sql_Connection = new SqlConnection(dict_SearchData["ConnectionString"]))
        {
            SqlCommand sql_Command = new SqlCommand(str_Query, sql_Connection);
            sql_Connection.Open();
            SqlDataReader sql_Reader = sql_Command.ExecuteReader();
            try
            {
                sql_Reader.Read();
                str_FieldValue = sql_Reader[0].ToString();
            }
            catch (System.InvalidOperationException)
            {
                //ignore the exception 
            }
            finally
            {
                // Always call Close when done reading. 
                sql_Reader.Close();
            }
        }

I added the port number to the connection string and I was able to connect to the database remotely with the application. 我将端口号添加到连接字符串中,并且能够使用该应用程序远程连接到数据库。 I added the port number after the ip address following the comma. 我在逗号后面的IP地址后面添加了端口号。

return @"Data Source= 2.2.2.2,1433\SQLEXPRESS; Persist Security Info=False;User ID=myusername;Password=mypassword;Initial Catalog=SomeDataStructure;";

It looks like your connection string may have extra characters or be formatted incorrectly. 看来您的连接字符串可能包含多余的字符或格式错误。 Try taking the extra step of putting the string in a local string variable, then assigning it to the ConnectionString object. 尝试采取额外的步骤,将字符串放入本地字符串变量,然后将其分配给ConnectionString对象。 This way you can step through the code and inspect the string value discretely. 这样,您可以单步执行代码并离散检查字符串值。 Also, the more common custom is to specify the server name as opposed to the ip address, although I would think either should work. 另外,更常见的习惯是指定服务器名称而不是IP地址,尽管我认为两者都应该起作用。 Also, that backslash may be creating problems, might have to escape that character. 同样,反斜杠可能会产生问题,可能必须转义该字符。

暂无
暂无

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

相关问题 使用C#的SQL上的错误26,指定了错误定位服务器/实例 - Error 26 on SQL with C#, 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? SQL Server EXPRESS:错误:26-在安装后指定服务器/实例时出错 - SQL Server EXPRESS: Error: 26 - Error Locating Server/Instance Specified after setup 错误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 在我的VM上:SQL网络接口,错误:26-查找指定的服务器/实例时出错 - on my VM: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM