How to detect SQLServer 2005 ?

A

ad

How can I detect if my computer have installed SQLServer 2005 or SQLServer
2005 Express with program like c# or VB.NNET?
 
G

GuangXiN

using System.ServiceProcess;
private void button1_Click(object sender, System.EventArgs e)
{
if(ExistSqlServerService())
{
MessageBox.Show("This computer has installed SQLServer");
}
else
{
MessageBox.Show("This computer hasn't installed SQLServer");
}
 
D

Duy Lam

GuangXiN said:
using System.ServiceProcess;
private void button1_Click(object sender, System.EventArgs e)
{
if(ExistSqlServerService())
{
MessageBox.Show("This computer has installed SQLServer");
}
else
{
MessageBox.Show("This computer hasn't installed SQLServer");
}


where is ExistSqlServerService() method ?
 
D

Duy Lam

ad said:
How can I detect if my computer have installed SQLServer 2005 or SQLServer
2005 Express with program like c# or VB.NNET?


Just execute a simple sql command to get it.

SqlCommand cmd = new SqlCommand(@"select @@VERION");
IDataReader drd = cmd.ExecuteReader();
drd.Read();
string version = drd.GetString(0);
// find version in string
if( version.Contain("Express") )
{
// Oh, we are in Express version
}
 
G

GuangXiN

I miss some code

public static bool ExistSqlServerService() {
bool flag = false;
ServiceController[] services = ServiceController.GetServices();
for(int i = 0; i < services.Length; i++) {
if(services.DisplayName.ToString().Equals("MSSQLSERVER") {
flag = true;
break;
}
}
return flag;
}
 
A

Arne Vajhøj

GuangXiN said:
I miss some code

public static bool ExistSqlServerService() {
bool flag = false;
ServiceController[] services = ServiceController.GetServices();
for(int i = 0; i < services.Length; i++) {
if(services.DisplayName.ToString().Equals("MSSQLSERVER") {
flag = true;
break;
}
}
return flag;
}


The service can have different names.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top