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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test server name

Status
Not open for further replies.

datras

Programmer
Jun 6, 2001
28
0
0
DK
Do someone know how I test what SQL server I am connected to in vd.net? I am working on both a production server and a development server and the code will be slightly different depending on what SQL server the vb.net code is linked to. So I would like to be able to test the SQL server name or data source in the connection string.

Thanks!
 
You can't test what SQL Server you are connected to unless you have connected to it (and therefore you would have to know the connection string in advance)!

If you meant you wanted to test which environment you were in you could use:
Code:
My.Computer.Name


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I am connected to the server and I do have the connection string so I can make a inStr search on the string, but is that the way to do it?
 
OK, if you are already connected to it, then you must have known which connection string to use. For example, in your scenario, presumably you had two connection strings and you used a certain one based on whether you were on the production or development server. As you have already made this choice then why would you have to search the connection string to find it out again? Couldn't you just use the same logic that you used to make the choice of which connection string to use?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
well, when moving the project from one server to another the DBserver (the IP address of the server) is changed manually in the global.xml. However, I would like that I don't have to change my part of the code every time I make a new version and move the it to the production server and therefore I need to make a test on the connection string.
 
In that case, you could either use the IndexOf method to check the connection string or have two connection strings and use the relevant one based on the environment (i.e. the method I showed above).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I tested the indexOf and it worked. Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top