Derbie
Derbie

Reputation: 423

WCF : remote SQL Server 2005 database connection

I'd like to know how to link my WCF application with a remote SQL Server database. By remote, I mean that is on the same network than me but not on the same computer/project. I've the controll of the computer where the database is stored on.

What I've done so far : create my WCF application and try to add an ADO.NET connection. My issue : where to find the name of the server ? (and also : is it the good way to proceed ?).

Thanks !

Upvotes: 0

Views: 495

Answers (3)

Marc Gravell
Marc Gravell

Reputation: 1062865

where to find the name of the server?

Three options:

  • whoever "owns" the database server tells you the details, and you put them in a configuration file (or some other configuration system)
  • whoever "owns" the database server tells some key user the details, and the user puts them into a screen / api in the application
  • something like the above, but you try to discover sql servers at runtime via SqlDataSourceEnumerator (not a fan of this option, to be honest)

Upvotes: 2

Jibran Khan
Jibran Khan

Reputation: 3256

I suggest you add connectionString in the Web.config file of the application

<add name="connectionString"
      connectionString="Data Source=ServerName/PC-Name;Initial Catalog=DatabaseName;User ID=userid;Password=pass"
      providerName="System.Data.SqlClient" />

Use the connection string in your code/Logic

string conn = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;

Upvotes: 1

Satpal
Satpal

Reputation: 133403

Conntion string should look like

 Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;Password=myPassword;

In Place of myServerName you can use IPAdress of machine

Upvotes: 1

Related Questions