Determining SQL Server 2008 Instance Name?

Discussion in 'ASP .Net' started by Jason, Sep 27, 2010.

  1. Jason

    Jason Guest

    I'm building a "Setup and Deployment" project to distribute our
    application. We have a database called dbMain that runs on SQL Server
    2008. I'm connecting to the database from our WPF Application via the
    app.config file, and here are the particulars:

    ---------------------------------------------------------------------------------------------------------------------------------------------------------------

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <configSections>
    </configSections>
    <connectionStrings>
    <add name="ConnectionString"
    connectionString="Data Source=.\SSE2008;AttachDbFilename=|
    DataDirectory|\DB\dbMain.mdf;Integrated Security=True;User
    Instance=True"
    providerName="System.Data.SqlClient" />
    </connectionStrings>
    </configuration>

    ---------------------------------------------------------------------------------------------------------------------------------------------------------------

    As you can see, the connection string is:

    Data Source=.\SSE2008;AttachDbFilename=|DataDirectory|\DB
    \dbMain.mdf;Integrated Security=True;User Instance=True

    Since our database is "dbMain.mdf", and the install script installs it
    into the DB folder, I have no problems with that. The problem arises
    with the Data Source=.\SSE2008

    Since I have no control over the Sql Server 2008 install, or what
    instance name the guy who set it up gave it, this program will bomb
    when run as is (as SSE2008 is the name I gave my SQL Server 2008
    instance).

    Is there are way to determine the instance of the SQL Server 2008
    instance at runtime (when the program gets the configuration string)
    and modify it so that the program will not bomb?

    What is the best way to handle this situation programmatically ( or is
    there ? )?

    Thanks,
    Jason
     
    Jason, Sep 27, 2010
    #1
    1. Advertising

  2. Jason

    Cubaman Guest

    On Sep 27, 8:15 pm, Jason <> wrote:
    > I'm building a "Setup and Deployment" project to distribute our
    > application.  We have a database called dbMain that runs on SQL Server
    > 2008.  I'm connecting to the database from our WPF Application via the
    > app.config file, and here are the particulars:
    >
    > ---------------------------------------------------------------------------------------------------------------------------------------------------------------
    >
    > <?xml version="1.0" encoding="utf-8" ?>
    > <configuration>
    >     <configSections>
    >     </configSections>
    >     <connectionStrings>
    >         <add name="ConnectionString"
    >             connectionString="Data Source=.\SSE2008;AttachDbFilename=|
    > DataDirectory|\DB\dbMain.mdf;Integrated Security=True;User
    > Instance=True"
    >             providerName="System.Data.SqlClient" />
    >     </connectionStrings>
    > </configuration>
    >
    > ---------------------------------------------------------------------------------------------------------------------------------------------------------------
    >
    > As you can see, the connection string is:
    >
    > Data Source=.\SSE2008;AttachDbFilename=|DataDirectory|\DB
    > \dbMain.mdf;Integrated Security=True;User Instance=True
    >
    > Since our database is "dbMain.mdf", and the install script installs it
    > into the DB folder, I have no problems with that.  The problem arises
    > with the Data Source=.\SSE2008
    >
    > Since I have no control over the Sql Server 2008 install, or what
    > instance name the guy who set it up gave it, this program will bomb
    > when run as is (as SSE2008 is the name I gave my SQL Server 2008
    > instance).
    >
    > Is there are way to determine the instance of the SQL Server 2008
    > instance at runtime (when the program gets the configuration string)
    > and modify it so that the program will not bomb?
    >
    > What is the best way to handle this situation programmatically ( or is
    > there ? )?
    >
    > Thanks,
    > Jason


    In Sql Management Studio:

    SELECT @@SERVERNAME

    But you can't connect to a service wich name/location is unknown.. So,
    ask your dba for right credentials.

    Best regards
     
    Cubaman, Sep 28, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shapper

    Windows 2008 and SQL 2008

    shapper, Dec 8, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    366
    Mark Fitzpatrick
    Dec 8, 2007
  2. AAaron123
    Replies:
    6
    Views:
    2,571
    AAaron123
    Oct 28, 2008
  3. Marek G.

    IIS 7 , 2008 R2 and SQL 2008

    Marek G., Feb 23, 2010, in forum: ASP .Net
    Replies:
    2
    Views:
    1,005
    Marek
    Feb 24, 2010
  4. Wesley Chen
    Replies:
    0
    Views:
    242
    Wesley Chen
    Apr 7, 2009
  5. Wesley Chen
    Replies:
    9
    Views:
    258
    Sean O'Halpin
    Apr 14, 2009
Loading...

Share This Page