How to find out what the server name is?

F

fiaolle

Hi
I'm woundering how I will find out what the SQL Server name is, without
running a stored procedure or something. Because if I am going to run a
stored procedure I have to know the server name. For example in the code
below I have to know the server name (.\\SQLEXPRESS) or do I or is there
another way to come around this?
The problem is I have two instances, SQL Server Express on one computer and
SQL Server
Enterprice on another computer. I don't want to have to change the
connectionstring in my application, when I'm moving the application to the
other computer.
 
P

Patrice

Generally the connection string is stored outside of the application (in the
application config file for example) so that you don't have to recompile
when you move the application...

The app has now way to guess. At some point you need to know on whihc server
you wan't to connect (for example what if you have multiple instances on the
same machine).
 
G

Gregory A. Beamer

I don't want to have to change the
connectionstring in my application, when I'm moving the application to
the other computer.

This is the way connection strings work. Unless you want to add some
bloated discovery mechanism to find all local instances, you will have
to alter connection strings.

This does not mean you end up having to go through too much trouble to
deploy an application, however, as you can exclude the config from
publish (web app) or put a postbuild in release (other app type) to
remove the config and then deploy only the bits (note that any real
changes to config will require changes to production config).

In VS2010, there are new deploy options for web apps that reduce the
pain of deploying (I forgot to exclude the config) to make things
easier.

But without kludging up the system, you are not going to have a single
connection string for SqlExpress and Enteprise unless you name your
local SQL Express install the same instance name as the server (provided
it is set up as an instance). Not sure if you can make SQL Express the
default instance(non-explicitly instanced, i.e. (local)), so this may be
a non option.

It would be nice to have the story you like, but I don't think it is
going to happen unless the Enterprise server is set to an instance name.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 

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