Determining SQL Server 2008 Instance Name?


J

Jason

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
 
Ad

Advertisements

C

Cubaman

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top