CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2006
    Location
    Graz, Austria
    Posts
    273

    server instance name

    Hi,
    Does anyone know how to read from c# if sql server is installed and more : what is the server name?

    Thanks
    Daniela
    ******
    I would love to change the world, but they won't give me the source code

  2. #2
    Join Date
    Mar 2006
    Location
    Graz, Austria
    Posts
    273

    [resolved]Re: server instance name

    Hi, I managed it.
    Daniela
    ******
    I would love to change the world, but they won't give me the source code

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: [resolved]Re: server instance name

    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.

  4. #4
    Join Date
    Mar 2006
    Location
    Graz, Austria
    Posts
    273

    Re: server instance name

    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
    Daniela
    ******
    I would love to change the world, but they won't give me the source code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured