Georgios
Georgios

Reputation: 1483

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.

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

I placed "tcp" because is what I met googling for connecting to a remotely database over IP(my case). 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.

Expanding the error message gives me the bellow description: Error message

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.

Except all, in the Catalog I am placing the name of the database right?

Upvotes: 0

Views: 514

Answers (2)

Zumarta
Zumarta

Reputation: 145

You can try forcing the usage of TCP/IP instead of named pipes for your connection with: Network Library=DBMSSOCN; after the Data Source element.

Upvotes: 0

Pikoh
Pikoh

Reputation: 7703

XML is case-sensitive. The S in string must be capital:

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

Upvotes: 2

Related Questions