How can I detect if my computer have installed SQLServer 2005 or SQLServer
2005 Express with program like c# or VB.NNET?
GuangXiN - 16 Mar 2008 07:26 GMT
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");
}
"ad" <flying@wfes.tcc.edu.tw>
2306S3xhIHA.1132@TK2MSFTNGP06.phx.gbl...
> How can I detect if my computer have installed SQLServer 2005 or SQLServer
> 2005 Express with program like c# or VB.NNET?
Duy Lam - 16 Mar 2008 11:24 GMT
> using System.ServiceProcess;
> private void button1_Click(object sender, System.EventArgs e)
[quoted text clipped - 12 lines]
>> How can I detect if my computer have installed SQLServer 2005 or SQLServer
>> 2005 Express with program like c# or VB.NNET?
where is ExistSqlServerService() method ?

Signature
Thanks,
Duy Lam Phuong
GuangXiN - 16 Mar 2008 12:17 GMT
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[i].DisplayName.ToString().Equals("MSSQLSERVER") {
flag = true;
break;
}
}
return flag;
}
Arne Vajhøj - 17 Mar 2008 02:56 GMT
> I miss some code
>
[quoted text clipped - 9 lines]
> return flag;
> }
The service can have different names.
Arne
Duy Lam - 16 Mar 2008 11:29 GMT
> 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
}

Signature
Thanks,
Duy Lam Phuong
Duy Lam - 16 Mar 2008 11:30 GMT
> How can I detect if my computer have installed SQLServer 2005 or SQLServer
> 2005 Express with program like c# or VB.NNET?
By the way, refer this link:
http://sqlserver2000.databases.aspfaq.com/how-do-i-know-which-version-of-sql-ser
ver-i-m-running.html

Signature
Thanks,
Duy Lam Phuong