C# 为远程托管的 SQL Server 定义 connectionString

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12121542/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 22:09:00  来源:igfitidea点击:

Defining connectionString for remotely hosted SQL Server

c#asp.netsql-serverconnection-string

提问by Luke

At the moment I have the following <connectionStrings> definition in myWeb.config` file:

目前我有以下<connectionStrings> definition in myWeb.config` 文件:

  <connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
  </connectionStrings>

I didn't write this though, so I have a feeling that it was automatically created by Visual Studio.

不过这不是我写的,所以我感觉它是由 Visual Studio 自动创建的。

My database is hosted on a separate server on our network, so how do I define it and the database username and password?

我的数据库托管在我们网络上的单独服务器上,那么我如何定义它以及数据库用户名和密码?

For the sake of the example, the server information and credentials are:

就示例而言,服务器信息和凭据为:

Server address: sql-database / 10.0.0.11

Username: myUsername

Password: myPassword

服务器地址:sql-database / 10.0.0.11

用户名:我的用户名

密码:我的密码

采纳答案by Vishal Suthar

Server Name: IP-Address\Database-instance,Port

服务器名称: IP-Address\Database-instance,Port

You can not directly. you need to have TCP/IPenabled and configured the TCP/IP Portson sql server configuration manager at remote server.

你不能直接。您需要在远程服务器上TCP/IP启用和配置TCP/IP Portssql server 配置管理器。

Go through it: Configurations-Remote-Server

通过它:配置-远程-服务器

Or if it already configured then just contact DBAfor the hosted server for providing the proper connection string.

或者,如果它已经配置,那么只需联系DBA托管服务器以提供正确的连接字符串。

you need to have TCP/IP connectivity .Just launch it, enter the DNS host name or IP address in the Server Name'box and hit Connect. The hosting company needs to have enabling TCP/IP on your SQL Server instance, and them providing you with secure access to the IP address that instance is running on.

你需要有 TCP/IP 连接。只需启动它,在Server Name'框中输入 DNS 主机名或 IP 地址,然后点击连接。托管公司需要在您的 SQL Server 实例上启用 TCP/IP,并且他们为您提供对运行该实例的 IP 地址的安全访问。

Then it would be in this form:

那么它将是这种形式:

connectionString="Data Source=Server_Name;Initial Catalog=Database_Name;
User ID=XXXX;Password=XXXX;Integrated Security=True;"
providerName="Provider_Name"

Most administrators do not allow direct access to the SQL Server from outside the firewall. In that case, if you can connect to the host over VPN then you should be able to connect directly to the server with Enterprise Manager or SQL Management Studio.

大多数管理员不允许从防火墙外部直接访问 SQL Server。在这种情况下,如果您可以通过 VPN 连接到主机,那么您应该能够使用 Enterprise Manager 或 SQL Management Studio 直接连接到服务器。

回答by Waqar Janjua

Modify your connection string as

将您的连接字符串修改为

connectionString = "data source=sql-database / 10.0.0.11; User ID = myUsername; PassWord = your password "

回答by Krishna Thota

Try using Connection String in this Format

尝试使用这种格式的连接字符串

<connectionStrings>
<add name="SQLconnString" connectionString="Data Source=246.185.231.253;Initial Catalog=DNAME;User ID=SampleUID;Password=SamplePWD;timeout=6000" />
</connectionStrings>

This Might help you!

这可能会帮助你!