Check available SQL DAtabase Server
I am working on a C# windows application which sends data to MS SQL database server. We have two Data servers on different places with different names containing same data. I want to check for available Data server before sending data to any server, because if sometime data server is not available then application will give exception & updates for that event will not be recorded in any of data server.
Please help.
thanks in advance :)
Swetha SrinivasanPosted Sep 7, 2009, 2:27 AM
I hope this solves your problem
Kirtan PatelPosted Aug 23, 2009, 11:42 AM
Project > Add Reference > Select Microsoft.SqlServer.smo and Click OK
Step 2
Then Write Code Like Below
Import the Namespace
dont forget to mark "Do you like answer" it will give me some credits :)
using Microsoft.SqlServer.Management.Smo;
private void btnGetServers_Click(object sender, EventArgs e)
{
List<string> ServerList = new List<string>();
DataTable dt = SmoApplication.EnumAvailableSqlServers();
foreach (DataRow dr in dt.Rows)
{
//Add Available Servers in comboBox
comboBox1.Items.Add(dr["Name"].ToString());
}
}