Click to See Complete Forum and Search --> : server instance name
DanielaTm
May 31st, 2006, 03:58 AM
Hi,
Does anyone know how to read from c# if sql server is installed and more : what is the server name?
Thanks
DanielaTm
May 31st, 2006, 10:01 AM
Hi, I managed it.
Shuja Ali
May 31st, 2006, 10:10 AM
It would better if you post what you did. This might help someone else who is having a similar kind of problem. Afterall we all are here to share and learn from others.
DanielaTm
May 31st, 2006, 10:19 AM
Hi,
I parsed from c# the registry looking for Sql server like this:
The code isn't yet improved, but it works. Maybe could be useful to someone.
using Microsoft.Win32;
RegistryKey baseRegistryKey = Registry.LocalMachine;
string subKey = "SOFTWARE\\Microsoft\\Microsoft SQL Server";
public void Read()
{
RegistryKey rk = baseRegistryKey;
RegistryKey sk1 = rk.OpenSubKey(subKey);
if (sk1 != null)
{
try
{
RegistryKey subk = sk1.OpenSubKey("Instance Names\\SQL");
if (subk != null)
{
valuekeys = subk.GetValueNames(); //returns the names of //instance(s) of sql server installed
}
}
catch (Exception e)
{
//to add
}
}
}
Hope it helped
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.