Johnseito
Johnseito

Reputation: 315

VB code to connect to SQL server on windows server 2012R2 - not locally

I know how to connect to SQL server Management studio locally, the one to your desktop, Windows Authentication. Code is as below.

myconnection As New SqlConnection("data source =serverNAME01; initial catalog=ZPCD; integrated security=true")

But how do I connect to SQL server Management Studio on Windows Server 2012R2, SQL Server Authentication from my desktop ?

The computer and username for remote desktop connection to Windows Server 2012R2 are:
computerNAME01,
userNAME01

The server name, login, password and IP address to management studio (database engine) are:

Server name: serverName01

Login: sa

Password: Password01

IP: 192.167.1.21

and database name is ZPCD

enter image description here

This is an example of my code, but it doesn't work.

connetionString="Data Source=192.167.1.21,1433;
    Network Library=DBMSSOCN;   Initial Catalog=ZPCD;
    User ID=sa;Password=Password01"

Error Message:

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

Upvotes: 0

Views: 1225

Answers (3)

Prescott Chartier
Prescott Chartier

Reputation: 1653

This is the format of the connection string I use. The format (apparently) changed in VB.NET from VS 2008 to VS 2010. When I upgraded my software from VS 2008 to VS 2010, it failed to connect to Sql Server. Took me hours to figure it out:

connectionString="server=192.168.1.1;database=MyDb;uid=sa; pwd=MyPassword" providerName="System.Data.SqlClient"

R/ Prescott ....

Upvotes: 0

Das Nuk
Das Nuk

Reputation: 46

Remote connection string should look like so.

SqlConnection("Server=192.167.1.21\sqlinstance; DATABASE=ZPCD; Connection Timeout=5; USER ID=SA; PASSWORD=Password01")

You need to have the SQL instance, the part in the () in image below after the \ after the IP address.

enter image description here

Can you post this from SQL Management Studio enter image description here

Upvotes: 0

RoMEoMusTDiE
RoMEoMusTDiE

Reputation: 4824

https://technet.microsoft.com/en-us/library/hh231672(v=sql.110).aspx

To enable the TCP/IP network protocol Start SQL Server Configuration Manager. Click Start, point to All Programs, and click Microsoft SQL Server. Click Configuration Tools, and then click SQL Server Configuration Manager. In SQL Server Configuration Manager, in the console pane, expand SQL Server Network Configuration. In the console pane, click Protocols for . In the details pane, right-click TCP/IP, and then click Enable. In the console pane, click SQL Server Services. In the details pane, right-click SQL Server (), and then click Restart, to stop and restart the SQL Server service.

Upvotes: 0

Related Questions