如何进行类连接来连接到远程数据库?
我有班级连接,但不起作用。它确实可以在同一网络(内联网)中工作,但不能在互联网上工作。
它是一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
服务器和公共互联网之间是否有防火墙?您是否必须更改防火墙规则或端口转发才能允许公共访问?您的计算机上是否运行了软件防火墙?请参阅 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 收到以下错误:
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:
这里有很多可能性。
我确信只要有更多的时间我就能想到其他人。
There are a lot of possibilities here.
I am sure I can think of others given a bit more time.
原始英文异常消息可在 www.unlocalize.com 以及现有解决方案的几个链接。
An original English exception message can be found at www.unlocalize.com as well as several links to existing solutions.