c# 4.0 - Insert into ms Access from SQL Server using OleDb provider -


in this post remou has nicely described how bulk insert data sql server table ms access table using following syntax:

select fld1, fld2 accesstable [sql connection string].sqltable 

in examples in post, remou using odbc keyword. how can modify examples if use sql server native client 10.0 ole db provider instead of sql server native client 10.0 odbc driver

for example, tried following not work. gives me error "could not find installable isam" on call executenonquery(). accessconn works fine i've tested odbc example of remou. issue seems connection string sql server.

oledbconnection accessconn = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source='c:\\testfolder\\test.mdb'"); oledbcommand accesscmd = new oledbcommand("insert table2 select * [oledb;provider=sqlncli10;server=myserver\\sqlexpress;database=testdb1;uid=testuser;pwd=testpassword].table1", accessconn); accesscmd.executenonquery(); accessconn.close(); 

thanks.

i suspect there isn't way describe using oledb.

i tested following vba code , worked:

sub odbctest() dim cdb dao.database, sql string set cdb = currentdb sql = _         "select id, lastname mycontacts " & _         "from [odbc;driver={sql server native client 10.0};server=.\sqlexpress;database=mydb;trusted_connection=yes;].dbo.mycontacts" cdb.execute sql, dbfailonerror end sub 

then, tested (what hoped be) oledb equivalent , failed same error got ("could not find installable isam.")

sub oledbtest() dim cdb dao.database, sql string set cdb = currentdb sql = _         "select id, lastname mycontacts " & _         "from [oledb;provider=sqlncli10;server=.\sqlexpress;database=mydb;trusted_connection=yes;].dbo.mycontacts" cdb.execute sql, dbfailonerror end sub 

but notice odbc; , oledb; prefixes inside square brackets: not needed when establishing "normal" connection. following code works...

sub adotest() dim con object const sqlinstance = ".\sqlexpress" set con = createobject("adodb.connection") con.open "driver={sql server native client 10.0};server=" & sqlinstance & ";database=mydb;trusted_connection=yes;" msgbox "odbc connection " & sqlinstance & " established." con.close set con = nothing end sub 

...but when add odbc; clause beginning of connection string...

sub adotest() dim con object const sqlinstance = ".\sqlexpress" set con = createobject("adodb.connection") con.open "odbc;driver={sql server native client 10.0};server=" & sqlinstance & ";database=mydb;trusted_connection=yes;" msgbox "odbc connection " & sqlinstance & " established." con.close set con = nothing end sub 

...it fails "[microsoft][odbc driver manager] data source name not found , no default driver specified".

so, odbc; prefix in first sub odbctest() code sample above clue from [odbc;...] method access shortcut pull data in odbc data source without explicitly creating linked table. (that stuff inside square brackets .connect property of tabledef object linked table.)

therefore, since far know access supports odbc linked tables (and not oledb linked tables), using method oldeb won't work.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -