【问题标题】:connectionString outside SQL server with App.config fileSQL Server 外部的 connectionString 与 App.config 文件
【发布时间】:2015-07-03 15:16:22
【问题描述】:

我有一个控制台应用程序,我需要在 App.config 中将一个 connectionString 添加到同一网络中的另一个 SQL 服务器。

如果我通过仅传递 Server='localhost' 来尝试将 connectionString 连接到本地服务器,它可以工作,但我无法使其适用于外部服务器。

谢谢

这是连接文件

<?xml version="1.0"?>
<configuration>
    <startup> 

    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
  <connectionStrings>
    <add connectionString="Server=LocalServer;database=DAtaBase;user=UserName;pwd=Password" name="Connection"/>
  </connectionStrings>
</configuration>

【问题讨论】:

  • 外部服务器的位置在哪里?告诉我们更多细节。
  • 请粘贴你的连接字符串和你得到的错误。
  • 我已经修改了问题并包含了连接配置文件
  • 这里是C# connectionstrings 的链接,它将向您展示如何将连接字符串配置到许多不同的数据库。还有Google could have saved you a lot of time and trouble 提问时请阅读faq 以了解如何提问这个网站上的问题以及
  • 您使用的是相同的 DNS 服务器实例名称对吗? IE。 SERVER=MySqlNode\WebSqlSERVER=10.0.0.4\SQLEXPRESS 等。另外,正如@MethodMan 所说,请阅读连接字符串。

标签: c# sql-server connection connection-string app-config


【解决方案1】:

与外部服务器的连接示例:

<connectionStrings>
    <add name="Namespace.Settings.outerSQL" connectionString="Data Source=192.168.0.100\SQLEXPRESS;Initial Catalog=database_name;User ID=user;Password=password"/>
</connectionStrings>

您需要提供远程服务器的地址和凭据(如果不是 Windows 身份验证,则使用“集成安全性”)。

【讨论】:

    【解决方案2】:

    在 app.config / web.Config 文件中,您将拥有以下内容,这是连接到 sql server 数据库的一种简单易行的方法。还请确认您正在使用的数据库,因为连接字符串可能不同取决于 DBMS

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <connectionStrings>
        <add name="DbConn" connectionString="Data Source=the name of your database;User Id=UserName;Password=Password;"/>
      </connectionStrings>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
      </startup>  
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-12
      • 2013-03-19
      • 1970-01-01
      • 2015-01-06
      相关资源
      最近更新 更多