Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get SQL Server name

Status
Not open for further replies.

mcauliff

Programmer
Feb 26, 2007
71
US
I have a VB.Net Console Application, it uses SQL Server. I have 4 SQL server/VB environments (DEv, QA, TrNg, Prod).

I want to retrieve the SQL Server name from a session variable is available.

How do I do this?

The other alternative is to pass it in, but don't know how to do this when the job is not schedule.
 
Aren't session variables a web thing? I'm not sure how it applies to a console application.
 
You can run a query against the database/instance, like this:

Code:
select @@ServerName As ServerName, db_name() As DatabaseName

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you for the reply.

Yes, Session Variables are for ASP pages. I hoping that there is a way to get the database server name.

Question on the Select suggestion from George. Doesn't it have to be connect to a database first? My problem is that I'm trying to find the server name, so that I can connect to the correct database in the VB.NET program. I have a app.config file that have the connection information depending on the environment.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top