Here's an Interesting 2 Questions

  • Thread starter Thread starter Michael C
  • Start date Start date
M

Michael C

1. Is there any way to retrieve the name of the locally running SQL Server?
The reason I ask is that I'd like to retrieve the name of the default SQL
Server and all named instances, but only on the local machine.

2. Is it possible to copy a file to a specified directory on a remote
machine without using shares? For instance, I might have a file like
"MYDATA.TXT" on my local machine, but I'd like to copy it to the "C:\TEST"
directory on a specific server; there are no shares set up on the server.

Thanks,
Michael C.
 
1. You'll need to enumerate the following key in the registry (assuming
you are running SQL Server 8.0):
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL
Server\InstalledInstances

2. If there are no shares on the target machine there is no native way
to put a file on that server. However, most servers come with default
adminstration shares for each hard drive (\\ServerName\C$ for C:\).
So, provided you have administrator access to the server and the shares
exist you can copy your file to \\servername\c$\test\

Hope this helps,

Reinout Hillmann
SQL Server Product Unit
 
Michael said:
1. Is there any way to retrieve the name of the locally running SQL Server?
The reason I ask is that I'd like to retrieve the name of the default SQL
Server and all named instances, but only on the local machine.

2. Is it possible to copy a file to a specified directory on a remote
machine without using shares? For instance, I might have a file like
"MYDATA.TXT" on my local machine, but I'd like to copy it to the "C:\TEST"
directory on a specific server; there are no shares set up on the server.

Thanks,
Michael C.
For number 1)
Add a reference to the COM object Microsoft SQLDMO
Then play with the following code:

System.Text.StringBuilder sb = new System.Text.StringBuilder();
SQLDMO.ApplicationClass ac = new SQLDMO.ApplicationClass();
for(int i=1;i<=ac.ServerGroups.Count;i++)
{
sb.Append("ServerGroup: ");
sb.Append(ac.ServerGroups.Item(i).Name);
for(int j=1;j<=ac.ServerGroups.Item(i).RegisteredServers.Count;j++)
{
sb.Append("\n");
sb.Append(ac.ServerGroups.Item(i).RegisteredServers.Item(j).Name);
}
sb.Append("\r\n");
}
MessageBox.Show(sb.ToString());

For some reason, the array of Item(s) starts at 1 instead of 0.
 
Back
Top