469,903 Members | 2,201 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

How to detect SQLServer 2005 ?

ad

How can I detect if my computer have installed SQLServer 2005 or SQLServer
2005 Express with program like c# or VB.NNET?
Mar 16 '08 #1
6 1768
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" <fl****@wfes.tcc.edu.tw>
23**************@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?

Mar 16 '08 #2
GuangXiN wrote:
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" <fl****@wfes.tcc.edu.tw>
23**************@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?


where is ExistSqlServerService() method ?

--
Thanks,
Duy Lam Phuong
Mar 16 '08 #3
ad wrote:
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
}

--
Thanks,
Duy Lam Phuong
Mar 16 '08 #4
ad wrote:
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.aspfa...m-running.html

--
Thanks,
Duy Lam Phuong
Mar 16 '08 #5
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;
}
Mar 16 '08 #6
GuangXiN wrote:
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;
}
The service can have different names.

Arne
Mar 17 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Roy Gourgi | last post: by
2 posts views Thread by =?Utf-8?B?SmVmZnJleQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.