Click here to Skip to main content
16,004,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello !

I am trying to enumerate Sql Server 2005 and above instaces installed on local machine.

I know that there is SMO. But SMO detects just Sql Server 2005 versions or lower. I have also tried to use registry but there is a problem with registry redirection.

I have x64 platform and my application is for x86 so it redirects me to ..\WOW6432NODE\...
Another posible solution would be to check service names but this can be very unreliable since the service can have any name as per user choice.

So, what's the solution? Can I use SMO for SQL Server 2008, or how can I skip the registry redirection from C#?(not with c++).

Thank you,
Bogdan
Posted
Updated 18-Aug-10 8:41am
v3

Here's[^] an implementation with c#.

Using this method you'll need to parse some strings, but it's a complete solution otherwise.

Cheers.
 
Share this answer
 
Yes, you can use SMO with SQL Server 2008. See here. Same for SQL Server 2005. I think you may want to use DMO for SQL Server 2000: http://support.microsoft.com/kb/326613.
 
Share this answer
 
SMO class structure changes very quickly. To support more and more functionality, most of the classes that were there in SQL server 2005 Management studio is changed in 2008.

So i think you need to recreate or modify your application to support them.

Other than that you can use Copy Local to all the dlls that you refer and ship the same with your application, and will let you do the code in any environment without using the dlls that are coming from GAC.

To do that, Just select the dll from Visual Studio Solution and go to properties. Select CopyLocal to true.

Now if you place the same solution to a machine which has SQL Server 2008, it will work.

:rose:
 
Share this answer
 
I've also read that SMO works with SQL Server 2008 but simply doesn't want to list my instances.
C#
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Management.Smo;
using System.Data;
namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            DataTable table = SmoApplication.EnumAvailableSqlServers(true);
            foreach (DataRow row in table.Rows)
            {
                Console.WriteLine("-- {0} -- {1} -- {2} -- {3} -- {4} -- ", row[0], row[1], row[2], row[3], row[4]);
            }
        }
    }
}


It just gets me the server name : BOGDAN-LAPTOP, not the instances;I have MSSQLSERVER and SQLEXPRESS 2008 instances.
I've tried the same code on a PC with SQL Srver 2005 instaces and works.

What's wrong with that ?
I've included the assembly from C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Smo.dll and also from C:\Program Files(x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Smo.dll because I have x64 Win 7, with the same result.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900