C# copy data from local SQL Server file to Access .mdb -




i use below code copy sql server table access file. have no problem when choose local sql server express database (created db ssms in local express area), have problem local file.

//using ace.oledb : oledbconnection accessconn = new oledbconnection(@"provider=microsoft.ace.oledb.12.0;data source="+setting.uniqefolderpath+"\\"+setting.uniqeid+".mdb");  accessconn.open();   //new table, using select  oledbcommand accesscommand = new oledbcommand(             @"select * "+desname+" ["+sourcename+ @"] in ''              [odbc;driver={odbc driver 11 sql server};server="+@"(localdb)\mssqllocaldb;             database='localdb';trusted_connection=yes];", accessconn);  accesscommand.executenonquery(); accessconn.close(); 

the problem happens when change database:

//error when change file address or file  oledbcommand accesscommand = new oledbcommand(     @"select * "+desname+" ["+sourcename+ @"] in '' [odbc;driver=     {odbc driver 11 sql server};server="+@"(localdb)\mssqllocaldb;     database='3b26bee4-2cdb-4d39-8400-7abb3debe802';trusted_connection=yes];", accessconn); 

i change database each below code:

database='3b26bee4-2cdb-4d39-8400-7abb3debe802'  database='3b26bee4-2cdb-4d39-8400-7abb3debe802.mdf'  database='c:\user\temp\uniquefolder\3b26bee4-2cdb-4d39-8400-7abb3debe802.mdf' 

visual studio show error :

additional information: odbc--connection '{odbc driver 11 sql server}(localdb)\mssqllocaldb' failed.

when change local express db created ssms, table copy access file.

 oledbcommand accesscommand = new oledbcommand(     @"select * "+desname+" ["+sourcename+ @"] in '' [odbc;driver=     {odbc driver 11 sql server};server="+@"(localdb)\mssqllocaldb;     database='localdb';trusted_connection=yes];", accessconn); 

problem: how copy data sql server local file access .mdb flie?

note: use sql server 2016 express , connect database (localdb)\mssqllocaldb

the way putting connection string odd, you've included connection string on command object, override properties in oledbconnection.

"[odbc;driver= {odbc driver 11 sql server};server="+@"localdb)\mssqllocaldb; database='localdb';trusted_connection=yes]"

get rid of connection string elements command, , specify connection string on oledbconnection object, only.

have @ https://www.connectionstrings.com/ if need more info on connection string should like.





wiki

Comments

Popular posts from this blog

python - Read npy file directly from S3 StreamingBody -

python - Minimize function with Scipy minimize -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -