How we get local SQL Server instance through c# -


i creating windows app in need create connection string automatically. create windows form similar sql server management studio connect server form. need few things

  1. local sql server name of system.

  2. after user fill form select server name , authentication type need check that filled details correct.

  3. i need create automatic connection string in c# , create automatic database , execute sql query in c# code working fine.

so me instance name , check data valid in c# window application.

to instances of local network (and local) can use code: (from msdn)

sqldatasourceenumerator instance = sqldatasourceenumerator.instance; system.data.datatable table = instance.getdatasources(); 

and test connection string can open connection generated connection string. this: (from this answer)

string provider = "system.data.sqlclient"; // example dbproviderfactory factory = dbproviderfactories.getfactory(provider); using(dbconnection conn = factory.createconnection()) {     conn.connectionstring = cs;     conn.open(); } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -