how do you do a class connection to connect to a remote database?
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;
}
pu开发者_Python百科blic void EjecutarConsulta(SqlCommand comando)
{
comando.Connection.Open(); // abrimos la conexion
comando.ExecuteNonQuery(); // ejecutamos la consulta
comando.Connection.Close(); // y cerramos la conexion
}
}
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
There are a lot of possibilities here.
- The SQL Server port is not open on the server in question.
- The SQL Server instances uses a non-standard port.
- The SQL Server instance does not have SQL Browser service on, so it does not accept remote connections.
- You have the wrong protocol to connect.
I am sure I can think of others given a bit more time.
An original English exception message can be found at www.unlocalize.com as well as several links to existing solutions.
精彩评论