Solved

how can i check sql server installation when my windows application start ??

Posted on 2011-03-01
9
314 Views
Last Modified: 2012-08-14
i want to know that whether sql server 2008 is installed or not on local pc when my window application start ??

please refer the below link ..

http://stackoverflow.com/questions/1221503/detect-local-sql-server-installation-with-c32-bit-as-well-as-64-bit

how can i put above coding when my application start ??

e.g in Program.cs file ?
0
Comment
Question by:Parth48
  • 4
  • 4
9 Comments
 

Author Comment

by:Parth48
ID: 35006277
can i change in program.cs file ??
0
 
LVL 8

Accepted Solution

by:
jimsweb earned 500 total points
ID: 35006318
I can see that the link you have provided above contians another link. It is :
http://stackoverflow.com/questions/1165576/c-how-to-get-sql-server-installation-path-programatically
It has the answer that you are looking for. :)
0
 
LVL 8

Expert Comment

by:jimsweb
ID: 35006323
Here is another easy tutorial that speaks about SQL server instance and installation. You can easily figure out the sam ein C# also.
http://stackoverflow.com/questions/2381055/check-if-sql-server-any-version-is-installed
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

Author Comment

by:Parth48
ID: 35006542
hi @jimsweb: u r right but can i put the below coding in program.cs file ??

      

using(RegistryKey sqlServerKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server"))
{
    foreach (string subKeyName in sqlServerKey.GetSubKeyNames())
    {
        if(subKeyName.StartsWith("MSSQL."))
        {
            using(RegistryKey instanceKey = sqlServerKey.OpenSubKey(subKeyName))
            {
                string instanceName = instanceKey.GetValue("").ToString();

                if (instanceName == "MSSQLSERVER")//say
                {
                    string path = instanceKey.OpenSubKey(@"Setup").GetValue("SQLBinRoot").ToString();
                    path = Path.Combine(path, "sqlserver.exe");
                    return path;
                }
            }
        }
    }
}

Open in new window


what can i do now ?

0
 
LVL 8

Expert Comment

by:jimsweb
ID: 35006569
Can you please try out the second one ..? It is working fine for me.
0
 

Author Comment

by:Parth48
ID: 35006616
ok @jimsweb: thanks ....
0
 

Author Comment

by:Parth48
ID: 35006634
but i can't find sql server version ??

is it work for sql server 2008 ??
0
 
LVL 8

Expert Comment

by:jimsweb
ID: 35006647
Console.WriteLine("Version:"+row["Version"]);

Open in new window


should write the version, i guess.
0
 
LVL 10

Expert Comment

by:wls3
ID: 35011907
You can possibly try the WMI class Win32_Product.  It's not as straightforward, but, can be effective.  This is mainly a snippet to give you an idea of what you are looking at from a code perspective.  Obviously, you'd just use code like this to perform your check.   I did a simple ASP.NET 4.0 website.  This all goes in the .cs page.  Querying WMI can usually take a while, so, you might want to do this as some sort of application initialization routine.  Also, you will need to add ConnectionOptions) to the ManagementScope in order to work with machines other than the localhost.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Management.Instrumentation;
using System.Security;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WMISearch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string sServerPath = @"\\" + Environment.MachineName + @"\root\cimv2";

        //Create a ManagementScope object
        ManagementScope Scope = new ManagementScope(sServerPath);

        //Connect to the COM interface
        Scope.Connect();

        //Create a new ObjectQuery
        ObjectQuery objectQuery = new ObjectQuery("SELECT * FROM Win32_Product WHERE (Name LIKE 'Microsoft SQL Server%')");
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(objectQuery);
        foreach (ManagementObject SQLServerInfo in searcher.Get())
        {
            Response.Write("Name: \t\t" + SQLServerInfo["Name"] + "<br/>");
            Response.Write("Version: \t\t" + SQLServerInfo["Version"] + "<br/>");
            Response.Write("IdentifyingNumber: \t" + SQLServerInfo["IdentifyingNumber"] + "<br/><br/>");
        }
    }
}

Open in new window

0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I hide MVVM menu items in WPF/XAML? 1 31
linq .concat equivalent with expression syntax 4 22
How to force output to ascii 2 31
Selenium and Xpath 4 28
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question