简体   繁体   English

带App.config文件的SQL Server外部的connectionString

[英]connectionString outside SQL server with App.config file

I have a console application and in the App.config I need to add a connectionString to another SQL server that is in the same network. 我有一个控制台应用程序,在App.config中,我需要将connectionString添加到同一网络中的另一个SQL Server。

If I try the connectionString to a local server by only passing the Server='localhost' its worked but I cannot make it work for an outside server. 如果我仅通过将Server ='localhost'传递给本地服务器,尝试将connectionString传递给本地服务器,则它不能工作,但不能使它适用于外部服务器。

Thanks 谢谢

Here is the connection file 这是连接文件

<?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>

Example connection to outer server: 与外部服务器的连接示例:

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

You need address to remote server and credentials provided (if it's not Windows auth, for which you use "Integrated Security"). 您需要提供远程服务器的地址和提供的凭据(如果不是Windows auth,则需要使用“集成安全性”)。

inside of a app.config / web.Config file you would have the following and this is a simple and easy way to connect to a sql server database.. also confirm what database you are using because the connection string can be different depending on the DBMS 在app.config / web.Config文件中,您将具有以下内容,这是连接到sql server数据库的简单方法。还要确认您使用的是哪个数据库,因为连接字符串可能会有所不同,具体取决于数据库管理系统

<?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>

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

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