Andres
Andres

Reputation: 4501

Connecting to a SQL Server database using VB.NET

I have to make a connection to a SQL Server database which is hosted at ip:aaa.xxx.yyy.zzz the user of this server is 'user' and password is 'password'. Database name is 'datos'

I tried this but it didn't work.

Dim myConn As SqlConnection
Dim myCmd As SqlCommand
Dim myReader As SqlDataReader
Dim results As String

myConn = New SqlConnection("Server=aaa.xxx.yyy.zzz;Database=datos;Trusted_Connection=True")
myConn.Open()

I also tried:

myConn = New SqlConnection("Server=aaa.xxx.yyy.zzz;Database=datos;User ID=user;Password=password")

EDIT

This code is into a sub named 'SQL', when it excecute myConn.Open() the sub finishes but shows no error.

Ip is on local network, and 'datos' was created on the local of the server using Microsoft SQL Server Management Studio

Upvotes: 2

Views: 110268

Answers (2)

G-Code101
G-Code101

Reputation: 31

No ports where declared in the IP eg .192.168.0.1:1033 , And instead of Database use Initial Catalog=datos

On the server you would have to set in sql server management the option of allowing remote connections to true, then in windows firewall activate the port used to connect to the sql server.

Full idea with the connection string...

"Server=192.168.0.1:1033\SQLEXPRESS;Initial Catalog=datos;uid=userid;pwd=password"

Upvotes: 3

E.J. Brennan
E.J. Brennan

Reputation: 46879

Could be a lot of things, since you didn't specify what error you got, but as a general reference this site: http://www.connectionstrings.com/sql-server/ gives you lots of things to try.

Other things to confirm: is the firewall allowing traffic thru? Is the port set to something other than the default of 1433; did you configure the server to allow remote connections? Is tcp/ip enabled?...etc.

Upvotes: 0

Related Questions