[英]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: string
的S
必须为大写:
<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.