How to add a linked sql server using LINQ in C#? -
i'm trying replace hardcoded sql queries linq expressions.
here's (simplified) code want replace:
list<string> sqlcommands = new list<string> { @"exec sp_attach_single_file_db @dbname='localdb', @physname=n'c:\dbfile.mdf'", @"exec sp_addlinkedserver @server='notlocaldb'" }; sqlconnection conn = new sqlconnection(@"server=.\sqlexpress; integrated security=true"); conn.open(); foreach (string commandstring in sqlcommands) { var command = new sqlcommand(commandstring, conn); command.executenonquery(); } conn.close();
i've replaced sp_attach_single_file_db
command linq statement:
dbdatacontext localdb = new dbdatacontext(@"server=.\sqlexpress; database=localdb; integrated security=true"); localdb.createdatabase();
but can't find equivalent command sp_addlinkedserver
.
is there way can create linked server localdb
using linq?
var connstringbuilder = new sqlconnectionstringbuilder(); connstringbuilder.datasource = ".\sqlexpress"; connstringbuilder.integratedsecurity = true; connstringbuilder.initialcatalog = "localdb"; sqlconnection conn = new sqlconnection(connstringbuilder)
Comments
Post a Comment