简体   繁体   English

如何通过App.config文件中的WPF使用IP连接到远程SQL数据库?

[英]How can I connect to a remotely SQL database using IP via WPF in App.config file?

Trying to connect in a remote database via IP using WPF, I place the following code in the App.config file. 尝试使用WPF通过IP连接到远程数据库时,我将以下代码放置在App.config文件中。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
  <connectionStrings>
    <add connectionString="Data Source=tcp:XXX.XXX.X.XX,1433; User Id=ex****;Password=ex*******; Initial Catalog=database_name;" name="ConString"/>
  </connectionStrings>  
</configuration> 

The above throws me a message that says "An unhandled exception of type 'System.TypeInitializationException' occurred in PresentationFramework.dll" 上面的消息让我说:“ PresentationFramework.dll中发生了'System.TypeInitializationException类型的未处理异常”

I placed "tcp" because is what I met googling for connecting to a remotely database over IP(my case). 我放置“ tcp”是因为我通过谷歌搜索通过IP连接到远程数据库(我的情况)。 Do I have other "options" instead of that? 我是否还有其他“选项”?

Notice that I am connecting over vpn and also that I have full access using SQL Management Studio. 请注意,我正在通过vpn连接,并且使用SQL Management Studio也具有完全访问权限。

Expanding the error message gives me the bellow description: 扩展错误消息给了我下面的描述: 错误信息

As I said I have full access in the remotely database via SQL Management Studio, so I suppose that the problem has to do with the syntax of the connectionstring code in App.config file. 就像我说的那样,我可以通过SQL Management Studio对远程数据库进行完全访问,因此我认为问题与App.config文件中的连接字符串代码的语法有关。

Except all, in the Catalog I am placing the name of the database right? 除所有之外,我是否在目录中放置数据库名称

XML is case-sensitive. XML区分大小写。 The S in string must be capital: stringS必须为大写:

<connectionStrings>
    <add connectionString="Data Source=tcp:XXX.XXX.X.XX,1433; User Id=ex****;Password=ex*******; Initial Catalog=database_name;" name="ConString"/>
</connectionStrings> 

You can try forcing the usage of TCP/IP instead of named pipes for your connection with: Network Library=DBMSSOCN; 您可以尝试通过以下方式强制使用TCP / IP代替命名管道: Network Library=DBMSSOCN; after the Data Source element. Data Source元素之后。

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

相关问题 在 WPF 中,如何绑定到 app.config 中 configSections 中的设置? - In WPF how can I bind to settings in configSections in app.config? 如何将SQL数据库添加到app.config文件? - How to add SQL database to the app.config file? 如何使用 App.config 将 C# 与 Db 连接起来? - How can I connect C# with Db with App.config? 我如何编辑app.config文件以使应用程序从同一文件夹附加数据库 - how can i edit the app.config file to let the application attach the database from the same folder 如何添加新的app.Config文件? - How Can I add new app.Config file? 修改app.config以连接到未安装SQL Server Management Studio的计算机中的数据库文件 - Modify app.config to connect to a database file in computer with no SQL Server Management Studio installed 需要通过C#中的app.config文件连接数据库 - Need to connect database through app.config file in C# 无法在WPF中使用App.config文件中的值 - Can't use values from App.config file in WPF 如何在不使用ModuleInfo标签的app.config的情况下使用C#使用Emc.Documentum.FS.Runtime连接到Documentum? - How can I connect to Documentum with Emc.Documentum.FS.Runtime using C# without the app.config for the ModuleInfo tags? 使用app.config文件连接到SAP公司对象 - Using the app.config file to connect to a SAP company object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM