Click here to Skip to main content
16,018,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
New to .net and wishing to create one windows form program that can be used by our internal users to directly access a SQL Server or sent to users outside our network that would instead use SQL Server Compact Edition. What would be the best way for the program to check if it has access to SQL Server and then connect to it if it does or if it does not, then connect to a SQL Server Compact database?

Thanks
Posted

1 solution

You can do this:
SqlDataSourceEnumerator sdse = SqlDataSourceEnumerator.Instance;
DataTable dt = sdse.GetDataSources();
Console.WriteLine("Avalaiable sources:");
foreach (DataRow dr in dt.Rows)
    {
    Console.WriteLine(dr["ServerName"]);
    }
If your server is in the list, it's available.
Note: you might want to do this in a background task: it takes a some seconds to scan your network.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900