sql connection string

ok i finally terminated a sql project.. Thanks God!

but.. 1 question remains:

this his the connection string used to connect to my DB

Data Source=MASTER\\SQLEXPRESS;Initial Catalog=tut;Integrated Security=True;Asynchronous Processing=True"

MASTER is my PC name;;

anyway i way to give to some friend thsi app so he can use it too..
but my app will connect to his database i mean the connection string wont be valid anymore.. so how can i make him automaticly detect or create the connection string..



Answer this question

sql connection string

  • Dietz

    Yes, it matches sql server 2000. It reports a different version number (8....) so you can distinguish the two, if needed. I couldn't test MSDE, so I cannot tell you what version is reported (as indicated before, SQL Server Express returns an empty version string).

    --mc


  • santamonicali

    "SQLExpress" in this case is the instance name of your database. I think you need to know the instance name of your database, I don't think there's a reliable way of automatically detecting that - and even if there was, it's possible to have more than one DB instance (or even the default instance, which doesn't have a name), so if this was the case, which one would you choose


  • James Lyvers

    If you only ever want to connect to the local machine, try replacing your local machine name (in this case MASTER) with a period (.).

    So your connection string would become:
    .\SQLEXPRESS;Initial Catalog=tut;Integrated Security=True;Asynchronous Processing=True


  • John Gallagher

    If you are running .NET 2.0 you may also use the new class SqlDataSourceEnumerator. You can use it as follows:

    System.Data.Sql.SqlDataSourceEnumerator en = System.Data.Sql.SqlDataSourceEnumerator.Instance;

    DataTable dt = en.GetDataSources ();
    foreach (DataRow dr in dt.Rows) {
    ... do whatever you want to determine if this is the correct instance ...
    }

    There is a good example in the msdn page. The DataTable that is returned contains a "ServerName", "InstanceName", "IsClustered" and "Version" columns. According to the documentation, the InstanceName will be empty if the instance is running as the default instance.

    I tried the above, and it does identify all the computers running a SQL Server instance in the local network (I get the correct ServerName for all of them). What I don't get is the InstanceName of the SQL Server Express (it is returned empty, while I would have expected a "SQLEXPRESS"). The good news is that apparently SQL Server Express returns an empty version number...

    HTH
    --mc


  • Simon Soanes

    Hi,
    assuming your friend used the default settings for the SQL instance, and you don't need anything fancy, you may simply try to change the machine name. You can get the computer name programmatically using the property:

    System.Environment.MachineName

    You might set your connection string to:

    @"Data Source={0}\SQLEXPRESS;Initial Catalog=tut;Integrated Security=True;Asynchronous Processing=True"

    string connStr = ... // get the string from wherever it is you keep it stored
    string connectionString = string.Format (connStr, System.Environment.MachineName);

    If you think your friend might have a full SQL Server and not just the express, you may want to try also with and withou the "\SQLEXPRESS".

    Again, this is a rather crude solution, but if it's just a matter of passing an app to a friend it should probably suffice.

    HTH
    --mc


  • Johnnie B.

    but still the SQLExpress remains.. what if he has full.. server


  • john hill

    yes i use .NET 2.0

    ok so i use.. GetDataSources method

    but what if the user has sql server 2000 will it match i mean does it has any impotance


  • sql connection string