RETAILREALM
asked on
find Local SQL Server Name
Hi
I want to find Local SQL Server Name
a) Without connecting to SQL database
b) SQLDMO object gives me “(local)” as Local SQL Server Name
c) Without using NetServerEnum API
ASKER
Thanks angelIII for quick reply
But I don’t find it suitable to search registry :( [Another Exclusion]
As I don’t know on which OS my application is going to run
I appreciate your help
You have any other idea for this ?
But I don’t find it suitable to search registry :( [Another Exclusion]
As I don’t know on which OS my application is going to run
I appreciate your help
You have any other idea for this ?
>But I don’t find it suitable to search registry :( [Another Exclusion]
why not? registry reading is not that difficult, and the registry location for the sql server does not change between windows versions.
>You have any other idea for this ?
no
why not? registry reading is not that difficult, and the registry location for the sql server does not change between windows versions.
>You have any other idea for this ?
no
ASKER
Thanks angelIII Let’s see if others have any answer to this
What SQL Server version?
ASKER
Thanks Nightman I have 8.00.194 But dont know which will client have
Dim oServer As SQLDMO.SQLServer
Set oServer = New SQLDMO.SQLServer
oServer.Connect "(local)" 'and whatever your credentials are
MsgBox oServer.NetName 'This is the servername (not the instance name!)
Dim qr As QueryResults
Set qr = oServer.ExecuteWithResults ("SELECT @@servername")
MsgBox qr.GetColumnString(1, 1) ' this will give you the instance name
I can't see an alternative other than connecting to the server, looking in the registry or enumerating the servers across the network.
HOWEVER, if you are SURE that your default instance will always be the servername, use the GetComputerName API
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
to use:
Dim liRet As Long
Dim sName As String
Dim liSize As Long
Dim sResult As String
sName = Space(255)
liSize = 255
liRet = GetComputerName(sName, liSize)
sResult = Left$(sName, liSize)
Does this help at all?
Set oServer = New SQLDMO.SQLServer
oServer.Connect "(local)" 'and whatever your credentials are
MsgBox oServer.NetName 'This is the servername (not the instance name!)
Dim qr As QueryResults
Set qr = oServer.ExecuteWithResults
MsgBox qr.GetColumnString(1, 1) ' this will give you the instance name
I can't see an alternative other than connecting to the server, looking in the registry or enumerating the servers across the network.
HOWEVER, if you are SURE that your default instance will always be the servername, use the GetComputerName API
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
to use:
Dim liRet As Long
Dim sName As String
Dim liSize As Long
Dim sResult As String
sName = Space(255)
liSize = 255
liRet = GetComputerName(sName, liSize)
sResult = Left$(sName, liSize)
Does this help at all?
ASKER
Thanks Nightman for your reply & code
But I don’t want to connect to database, as I don’t know which is ‘Local’ database
I am not sure about default instance :(
I am finding a way by which I just get the name of SQL server on my pc
Again many thanks for quick reply
Please let me know if u gets any thing
But I don’t want to connect to database, as I don’t know which is ‘Local’ database
I am not sure about default instance :(
I am finding a way by which I just get the name of SQL server on my pc
Again many thanks for quick reply
Please let me know if u gets any thing
You don't want to connect to the server, you don't want to use computer name, you don't want to look in the registry, and you don't want to enumerate them across the network?
With all due respect, there is no programatic crystal ball for you to look into to guess this information. And if none of these meet your requirements, consider changing your requirements.
With all due respect, there is no programatic crystal ball for you to look into to guess this information. And if none of these meet your requirements, consider changing your requirements.
ASKER
Thanks Nightman
I do understand this
Basically I want to check if this particular Sql servers are running suppose A,B,C
So if I use SQLDMO I may get 10 servers with one of them as ‘Local’ which may be ‘A’ and other two as B & C
So the Server ‘A’ is running but I don’t get its name L
That why my requirements is like this
If you have any other way please let me know
I do understand this
Basically I want to check if this particular Sql servers are running suppose A,B,C
So if I use SQLDMO I may get 10 servers with one of them as ‘Local’ which may be ‘A’ and other two as B & C
So the Server ‘A’ is running but I don’t get its name L
That why my requirements is like this
If you have any other way please let me know
I'm not sure I understand. Please correct me if I am wrong:
1. You use the DMO and one of the servers that is returned is called (local).
2. You want to determine the name of the SQL Server instance, which has to be running on the same machine where the DMO is being used.
3. Yet you can't connect to it, can't check the registry and can't enumerate server instances and can't assume the computer name.
I suspect that you are out of options.
1. You use the DMO and one of the servers that is returned is called (local).
2. You want to determine the name of the SQL Server instance, which has to be running on the same machine where the DMO is being used.
3. Yet you can't connect to it, can't check the registry and can't enumerate server instances and can't assume the computer name.
I suspect that you are out of options.
ASKER
Thanks Nightman
I agree to your point 1 & 2
I have thought a workaround on this
As I have connection details of servers I want to connect
So I will try with ‘local’ server
Dim oServer As SQLDMO.SQLServer
Set oServer = New SQLDMO.SQLServer
oServer.Connect "(local)" 'and whatever your credentials are
MsgBox oServer.NetName 'This is the servername (not the instance name!)
Dim qr As QueryResults
Set qr = oServer.ExecuteWithResults ("SELECT @@servername")
MsgBox qr.GetColumnString(1, 1) ' this will give you the instance name
And if any one is at all successful I will assume that ‘local’ =That Server. This seems to be working for me.
Thanks for your help
But still I think there must be some way to get the SQL server name from Computer
I am searching that else I would be happy to award points to you
I agree to your point 1 & 2
I have thought a workaround on this
As I have connection details of servers I want to connect
So I will try with ‘local’ server
Dim oServer As SQLDMO.SQLServer
Set oServer = New SQLDMO.SQLServer
oServer.Connect "(local)" 'and whatever your credentials are
MsgBox oServer.NetName 'This is the servername (not the instance name!)
Dim qr As QueryResults
Set qr = oServer.ExecuteWithResults
MsgBox qr.GetColumnString(1, 1) ' this will give you the instance name
And if any one is at all successful I will assume that ‘local’ =That Server. This seems to be working for me.
Thanks for your help
But still I think there must be some way to get the SQL server name from Computer
I am searching that else I would be happy to award points to you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Nightman
One more issue SQLDMO gives wrong status
Means even if I closed remote server, it gives me it as running
One more issue SQLDMO gives wrong status
Means even if I closed remote server, it gives me it as running
I guess you would have to reconnect to determine the status. That sounds about normal.
ASKER
Thanks Nightman
That not the case , anyways Thanks for your Help
That not the case , anyways Thanks for your Help
default instance:
HKLM\Software\Microsoft\Mi
named instance:
HKLM\Software\Microsoft\Mi