Parth48
asked on
how can i check sql server installation when my windows application start ??
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/q uestions/1 221503/det ect-local- sql-server -installat ion-with-c 32-bit-as- well-as-64 -bit
how can i put above coding when my application start ??
e.g in Program.cs file ?
please refer the below link ..
http://stackoverflow.com/q
how can i put above coding when my application start ??
e.g in Program.cs file ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
http://stackoverflow.com/questions/2381055/check-if-sql-server-any-version-is-installed
ASKER
hi @jimsweb: u r right but can i put the below coding in program.cs file ??
what can i do now ?
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;
}
}
}
}
}
what can i do now ?
Can you please try out the second one ..? It is working fine for me.
ASKER
ok @jimsweb: thanks ....
ASKER
but i can't find sql server version ??
is it work for sql server 2008 ??
is it work for sql server 2008 ??
Console.WriteLine("Version:"+row["Version"]);
should write the version, i guess.
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/>");
}
}
}
ASKER