2005 Express Connection String

  • Hi,

    My C# app uses SQL Server 2005 Express edition.

    I store my connection string in a config file.

    My application will run on numerous machines and therefore the machine name will be different each time. What I would like is a generic connection string so that I don't have to change it each time I install my app on a different machine.

    I therefore want to avoid specifing the machine name in the connection string as shown below :-

    "Data Source=MachineName;Initial Catalog=pubs;Integrated Security=SSPI;"

    Is there any way to make this connection string generic so that it can stay the same between different machines?

    Thanks

    Macca

  • See http://www.connectionstrings.com/

    and look under sql server 2005

  • you're going to have to put in a machine name somewhere to fill in the connection string.  it almost sounds like you are going to have the database for the application on the same machine as the application.  if this is the case, you can use a standard connection string, and at run time, fill in the local machine name.

    string ConnectString = GetFromConfig(ConnectionString)

    connectstring.replace('MachineName', SystemInformation.ComputerName)

    then connect as normal and do what the applicaiton needs.

  • If your app will run on the same machine as the database, you could try using localsystem as the server name, or even a full stop, like this:

     <connectionStrings>

      <add name="VS2005TESTConnectionString" connectionString="Data Source=.;Initial Catalog=YourDatabase;Integrated Security=True" providerName="System.Data.SqlClient"/>

     </connectionStrings>

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply