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
local sql server name of system.
after user fill form select server name , authentication type need check that filled details correct.
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
Post a Comment