resolve (local) to name of instance

  • Hi

    How do I resolve "(local)" in a vb application before I save the name into another sql server?

    What I want is to save an information on a server, let say where to finde some additional information. It works fine in all other senarios, but when I run the application on my own server, where I have a instance of sql server 2000 I get the "(local)" as the name of the instance. That would be okay if I can find a way to resolve this to the name of the instance (as seen from anyone elsewhere) before I save the name.

    Thanks in advance,

    Inger.

  • Run some of the following queries.  The results are given for a server named SERVER using a SQL Server Instance called INSTANCE.

    select ServerProperty('ServerName')   - returns SERVER\INSTANCE

    You could also look at

    select ServerProperty('MachineName')  - returns SERVER

    select ServerProperty('InstanceName') - returns INSTANCE

    or

    select @@SERVERNAME - returns SERVER\INSTANCE

    Note that if there is no instance then just SERVER is returned for the SERVERNAME property/variable.

    Also, according to books online, @@SERVERNAME doesn't report the correct name if you rename your server computer (eg from BACKUPSERV to PRIMARYSERV - it will still report BACKUPSERV).

    Good luck

  • I can get the name from the sql server like you told me, but I would like to resolve the name on the server/workstation where the application is run. "What is the name of your sql server (instance)?" without asking the sql server. Can it done?

    Thanks a lot for your help.

  • Hmmm...  Well on the workstation your software would have to store the server's name & instance so that's an application issue.

    As for on the server...  Do you just want to enumerate the instance names of all MSSQL instances installed?  If so, do you always install a new instance for your software with a particular name (rather annoying when other apps do this but could be for security reasons)?  If yes - then you know the name and probably wouldn't be asking

    So I don't quite understand your question?  How would the app be able to determine a SQL Server instance to connect to without a human giving it that instruction initially?

    If you mean to ask about where to store the server/instance name and how to read it back, you could store that in an ini file, the registry (local machine or current user depending on the app and how it is used in the enterprise) or in some other obscure location like a .NET config file

  • After I submitted it occurred to me that your overall question was about (local) and resolving that.

    For (local) without anything else in the servername, this would have no instance and would be equivalent to the loocal computer's name.  There are many ways to get this - some easier depending on your programming language.  But it is always available via the COMPUTERNAME environment variable which is usually pretty easy to get to.

  • Thanks for your help. I ended up asking for the COMPUTERNAME, and it seems to do the trick.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply