如何从 vb.net windows 窗体应用程序访问远程 sql server 数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27604416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to access remote sql server database from vb.net windows form application
提问by Shenoy
i want to develop an application with SQL Server 2008 and Vb.Net. my SQL server will running in one system and i want this server to be accessed by Vb application which is running in other computer (not in the same network/LAN).
我想用 SQL Server 2008 和 Vb.Net 开发一个应用程序。我的 SQL 服务器将在一个系统中运行,我希望该服务器可以被在另一台计算机上运行的 Vb 应用程序访问(不在同一网络/局域网中)。
my question is that,
我的问题是,
Is is possible to access SQL Server Database from remote computers(which are running in different network - different part of the world) ?
will it require that all the computers which are accessing this server should be in running in same "Domain" ?
是否可以从远程计算机(运行在不同的网络 - 世界的不同部分)访问 SQL Server 数据库?
是否要求所有访问该服务器的计算机都应该在同一个“域”中运行?
please help me in this.
请帮助我。
please provide a simple vb.net code( windows form application) which will connect to Remote SQL Server Database.
请提供一个简单的 vb.net 代码(windows 窗体应用程序),它将连接到远程 SQL Server 数据库。
Hearty thanks in advance..
提前衷心感谢..
回答by Jason Faulkner
To access a SQL database across the internet (using a non-VPN connection), you would need to use a connection string such as the following:
要通过 Internet 访问 SQL 数据库(使用非 VPN 连接),您需要使用如下连接字符串:
Data Source=x.x.x.x,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
- Data Source = Remote server. You can use either the IP or full DNS name. If you are using a non-standard port (something other than 1433), you can specify it after the comma.
- Initial Catalog = Database name on the remote server.
- User ID = SQLuser name and password. This will use SQL authentication, not integrated windows security.
- Password = Password for the respective User ID.
- 数据源 = 远程服务器。您可以使用 IP 或完整的 DNS 名称。如果您使用的是非标准端口(1433 以外的端口),您可以在逗号后指定它。
- 初始目录 = 远程服务器上的数据库名称。
- 用户 ID = SQL用户名和密码。这将使用 SQL 身份验证,而不是集成的 Windows 安全性。
- 密码 = 相应用户 ID 的密码。
A few things (warnings) about the remote server:
关于远程服务器的一些事情(警告):
- It will need to expose SQL through the internet. Firewalls would need to be configured to allow the connection to the SQL port.
- It will need to be set to allowed Mixed Mode authentication with SQL user accounts setup that you can use in your connection string.
- 它将需要通过 Internet 公开 SQL。需要配置防火墙以允许连接到 SQL 端口。
- 需要将其设置为允许使用可在连接字符串中使用的 SQL 用户帐户设置的混合模式身份验证。
Simple VB.NET Code is available lots of places. Here is a sampleon Microsoft's site. You would use the SqlClient connection information.
简单的 VB.NET 代码在很多地方都可用。这是Microsoft 网站上的示例。您将使用 SqlClient 连接信息。
回答by Abdallah A. Abdallah
You need to access the server/host computer where your database reside and connect to it via IP address from other client computers.
您需要访问数据库所在的服务器/主机,并通过 IP 地址从其他客户端计算机连接到它。
You can try this connection string - Data Source=Server/host IPaddress,1433;Network Library=DBMSSOCN; Initial Catalog= db_name;User ID=db_Username;Password=corresponding_password;
你可以试试这个连接字符串——Data Source=Server/host IPaddress,1433;Network Library=DBMSSOCN; 初始目录= db_name;用户ID=db_Username;密码=corresponding_password;
this works perfectly on my computers.
这在我的电脑上完美运行。
Source ~ SQLConnectionStrings.com
来源 ~ SQLConnectionStrings.com

