Winforms C # connection with remote SQL Server

0

I am developing an application with winforms which I need to connect to a remote server to share the data in an intranet to different machines.

The point is that I only want to install the SQL Server on the server and that the other PCs connect to it.

It is possible and if so what would be the format of the connection string since my current format is this

public ManejadorDatos()
{
    string usuario = ConfigurationManager.AppSettings["usuario"];
    string password = ConfigurationManager.AppSettings["clave"];
    string servidor = ConfigurationManager.AppSettings["servidor"];
    string dataBase = ConfigurationManager.AppSettings["dataBase"];

    Coneccion = new SqlConnection("user id=" + usuario +
                                  ";password=" + password +
                                  ";server=" + servidor +
                                  ";Trusted_Connection=yes;" +
                                  "database=" + dataBase +
                                  ";connection timeout=15");
}
    
asked by Junior Zapata 22.11.2016 в 14:58
source

2 answers

3

There may be several factors, I recommend you check all the following:

  • Your connectionString will be useful if you are on the same computer or in a VPN with Active Directory domain, otherwise you are not familiar with the topic I recommend using the connection per user and password of SQL Server as indicated by @ randall-sandoval, for this you must have SQL Server configured with Mixed authentication .

  • Verify that you have enabled remote access to SQL Server as indicated by @ pedro-Ávila.

  • Open ports for SQL Server in Windows Firewall.

  • If you are in the same network or in a remote network with VPN you should make sure you have connectivity between the client and the server, a way to validate it is with PING, as long as you are allowed to open the port in the Firewall .

  • If it is a remote server behind a router or Firewall on a Public IP, you must open the corresponding ports for SQL SERVER and configure the Port Forwarding to your SQL server, I recommend enabling the Ping on the router to validate that you have a response from the remote site.

This video covers several steps of the previous ones, I hope it serves you: link

    
answered by 23.11.2016 / 17:45
source
0

Of course you can install the SQL on a server and that the rest of the computers connect to that server (in fact that is the logic of a database, which is in one place - or a mirror on several servers - and that all inquiries and transactions are made there).

Now, what I recommend is that you make a connectionString in app.config or web.config .

<?xml version='1.0' encoding='utf-8'?>
<configuration>
  <connectionStrings>
      <add name="NombreConexion" 
       providerName="System.Data.ProviderName" 
       connectionString="Data Source = 192.168.200.1; Initial Catalog = MiBaseDatos; User Id = Usuario; Password = Contraseña;" />
  </connectionStrings>
</configuration>

The Data Source , is the ip of the server or the name assigned to it, e Initial Catalog is the database to which you want to connect, the User Id the name of the user with which you log in and Password the password corresponding to the user.

Now to read it, you must first add the reference to System.Configuration to the project, then with the following sentence:

String miConexion = ConfigurationManager.ConnectionStrings["NombreConexion"].ConnectionString;
Coneccion = new SqlConnection(miConexion);

Here are some references of a YouTube video and MSDN

    
answered by 22.11.2016 в 15:22