简体   繁体   English

使用VB.NET连接到SQL Server数据库

[英]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'. 我必须连接到ip:aaa.xxx.yyy.zzz托管的SQL Server数据库,该服务器的用户为“ user”,密码为“ password”。 Database name is 'datos' 数据库名称为“ 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. 该代码执行到名为“ SQL”的子代码中,当它执行myConn.Open()时 ,子代码完成但未显示任何错误。

Ip is on local network, and 'datos' was created on the local of the server using Microsoft SQL Server Management Studio IP位于本地网络上,并且使用Microsoft SQL Server Management Studio在服务器的本地上创建了“ datos”

No ports where declared in the IP eg .192.168.0.1:1033 , And instead of Database use Initial Catalog=datos IP中没有声明的端口,例如.192.168.0.1:1033,而不是数据库,请使用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. 在服务器上,您必须在sql服务器管理中设置允许远程连接为true的选项,然后在Windows防火墙中激活用于连接到sql服务器的端口。

Full idea with the connection string... 有关连接字符串的完整说明...

"Server=192.168.0.1:1033\\SQLEXPRESS;Initial Catalog=datos;uid=userid;pwd=password" “服务器= 192.168.0.1:1033 \\ SQLEXPRESS;初始目录= datos; uid =用户标识; pwd =密码”

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. 可能有很多事情,因为您没有指定遇到的错误,但是作为一般参考,该站点: http : //www.connectionstrings.com/sql-server/提供了很多尝试的方法。

Other things to confirm: is the firewall allowing traffic thru? 需要确认的其他事项:防火墙是否允许流量通过? Is the port set to something other than the default of 1433; 端口是否设置为默认值1433以外的值? did you configure the server to allow remote connections? 您是否配置服务器以允许远程连接? Is tcp/ip enabled?...etc. 是否启用了tcp / ip?...等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM