如何进行类连接来连接到远程数据库?

发布于 2024-11-03 05:20:30 字数 1425 浏览 2 评论 0原文

我有班级连接,但不起作用。它确实可以在同一网络(内联网)中工作,但不能在互联网上工作。

它是一个 SQL Server - 我有一个用户,一个通行证 - 这个私有 ip,公共 ip 是 189.148.67.149

我已将 SQL Server 配置为接受 tcp/ip,但应用程序无法工作:

与仆人 SQL Server 建立连接时出现与特定网络或实例相关的错误。不是仆人,或者这个人无法接近。它验证实例名称是否正确以及 SQL Server 是否允许远程连接。 (致提供商:TCP 供应商,错误:0 - 由于连接部分在一段时间后没有适当响应,在尝试连接期间发生错误,或者由于连接的主机尚未建立而在已建立的连接中发生错误能够回复。)

我用 http://es.babelfish.yahoo.com/translate_txt 西班牙语(我的语言)

与 SQL Server 服务器连接的红色或特定实例相关的错误。无法控制服务器或无法访问。包含正确的实例名称和 SQL Server 的配置以允许远程连接。 (提供者:TCP 提供商,错误:0 - 在连接双方的意图发生期间,生产过程中出现错误,但在连接双方没有响应的情况下,最好在连接双方建立连接时出现错误ha podido 响应者。)

class Conexion
{
     public SqlConnection conectar()
    {
        //my pc is called alumno-auc
        SqlConnection con = new SqlConnection(@"Data Source=192.168.1.82,1433;Initial Catalog=misnotas;Persist Security Info=True;User ID=login2; Password=login2; Asynchronous Processing=True;TrustServerCertificate=False;Network Library=dbmssocn;Workstation ID=alumno-auc;User Instance=False"); 
        return con;
    }

    public void EjecutarConsulta(SqlCommand comando)
    {
        comando.Connection.Open(); // abrimos la conexion
        comando.ExecuteNonQuery(); // ejecutamos la consulta
        comando.Connection.Close(); // y cerramos la conexion
    }
}

I have a class connection, but it doesn't work. It does work in the same network (intranet), but it doesn't work over the internet.

It is a SQL Server - i have a user, a pass- and this privated ip, public ip is 189.148.67.149

I had configured SQL Server to accept tcp/ip, but the application doesn't work:

Error related to the specific network or of the instance while a connection with servant SQL Server settled down. Was not the servant or this one was not accessible. It verifies that the name of the instance is correct and that SQL Server is formed to admit remote connections. (to provider: Supplier of TCP, error: 0 - An error took place during the attempt of connection since the connected part did not respond suitably after a period of time, or an error in the established connection took place since host connected has not been able to respond.)

I tranlated that with in http://es.babelfish.yahoo.com/translate_txt in spanish (my languaje)

Error relacionado con la red o específico de la instancia mientras se establecía una conexión con el servidor SQL Server. No se encontró el servidor o éste no estaba accesible. Compruebe que el nombre de la instancia es correcto y que SQL Server está configurado para admitir conexiones remotas. (provider: Proveedor de TCP, error: 0 - Se produjo un error durante el intento de conexión ya que la parte conectada no respondió adecuadamente tras un periodo de tiempo, o bien se produjo un error en la conexión establecida ya que el host conectado no ha podido responder.)

class Conexion
{
     public SqlConnection conectar()
    {
        //my pc is called alumno-auc
        SqlConnection con = new SqlConnection(@"Data Source=192.168.1.82,1433;Initial Catalog=misnotas;Persist Security Info=True;User ID=login2; Password=login2; Asynchronous Processing=True;TrustServerCertificate=False;Network Library=dbmssocn;Workstation ID=alumno-auc;User Instance=False"); 
        return con;
    }

    public void EjecutarConsulta(SqlCommand comando)
    {
        comando.Connection.Open(); // abrimos la conexion
        comando.ExecuteNonQuery(); // ejecutamos la consulta
        comando.Connection.Close(); // y cerramos la conexion
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

妳是的陽光 2024-11-10 05:20:30

服务器和公共互联网之间是否有防火墙?您是否必须更改防火墙规则或端口转发才能允许公共访问?您的计算机上是否运行了软件防火墙?请参阅 http: //www.sevenforums.com/system-security/58817-remote-access-sql-server-express-2008-windows-7-a.html 了解有关 Windows 7 for Sql Express 中的 Windows 防火墙的信息。

此故障排除指南应该会有所帮助 - http://blogs.msdn.com/b/sql_protocols/archive/2008/04/30/steps-to-troubleshoot-connectivity-issues.aspx

您确定希望您的 SQL 服务器公开互联网?如果您这样做,您确实必须知道如何管理您的安全。通常不建议这样做。

我尝试使用您提供的信息附加到您的服务器,但我从 SQL Server Management Studio 2008 收到以下错误:

标题:连接到服务器

无法连接到 189.148.67.149。

------------------------------------------ 其他信息:

与网络相关或特定于实例的
建立时发生错误
连接到 SQL Server。服务器
未找到或无法访问。
验证实例名称是否为
正确并且 SQL Server 是
配置为允许远程
连接。 (提供者:命名管道
提供商,错误:40 - 无法打开
连接到 SQL Server)(微软
SQL Server,错误:53)

如需帮助,请点击:
http://go.microsoft .com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=53&LinkId=20476

------------------------------------------ 按钮:

确定

Is there a firewall between the server and the public Internet? Do you have to change a firewall rule or port forwarding to allow public access? Do you have a software firewall running on the machine? See http://www.sevenforums.com/system-security/58817-remote-access-sql-server-express-2008-windows-7-a.html for info about Windows Firewall in Windows 7 for Sql express.

This troubleshooting guide should be helpful - http://blogs.msdn.com/b/sql_protocols/archive/2008/04/30/steps-to-troubleshoot-connectivity-issues.aspx

Are you sure you want your SQL server on the public Internet? You've really got to know how to manage your security if you are doing this. It is usually not recommended.

I attempted to attach to your server using the info you've supplied, I got the following error from SQL Server Management Studio 2008:

TITLE: Connect to Server

Cannot connect to 189.148.67.149.

------------------------------ ADDITIONAL INFORMATION:

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: Named Pipes
Provider, error: 40 - Could not open a
connection to SQL Server) (Microsoft
SQL Server, Error: 53)

For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=53&LinkId=20476

------------------------------ BUTTONS:

OK

愚人国度 2024-11-10 05:20:30

这里有很多可能性。

  1. SQL Server 端口在相关服务器上未打开。
  2. SQL Server 实例使用非标准端口。
  3. SQL Server 实例没有启用 SQL Browser 服务,因此它不接受远程连接。
  4. 您连接的协议有误。

我确信只要有更多的时间我就能想到其他人。

There are a lot of possibilities here.

  1. The SQL Server port is not open on the server in question.
  2. The SQL Server instances uses a non-standard port.
  3. The SQL Server instance does not have SQL Browser service on, so it does not accept remote connections.
  4. You have the wrong protocol to connect.

I am sure I can think of others given a bit more time.

何以心动 2024-11-10 05:20:30

原始英文异常消息可在 www.unlocalize.com 以及现有解决方案的几个链接。

An original English exception message can be found at www.unlocalize.com as well as several links to existing solutions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文