SQL Server ODBC Linked Server

454 Views Asked by At

I'm trying to create a linked server in SQL Server 2017, linked system is odbc (criteria criOdbc)

Test 1 from SQL Server Management Studio:

select * 
from OPENROWSET('MSDASQL',
                'DSN=criteria64;uid=xxxx;pwd=yyyy;',
                'select * from table where key < 10')

I get this error

Error converting data type DBTYPE_DBDATE to date

Test 2 from SQL Server Management Studio:

select * 
from OPENROWSET('MSDASQL',
                'DSN=criteria64;uid=xxxx;pwd=yyyy;',
                'select key from table where key < 10')

This works perfectly

Test 3 in C# (load from odbc then bulk insert into SQL Server):

OdbcConnection acc = new OdbcConnection("DSN=criteria64;uid=xxxx;pwd=yyyy;")
OdbcCommand cmd = new OdbcCommand("select * from table where key<10", acc);
....

This again works perfectly

Test 4 connect the same table in MS Access as a linked table:

This also works perfectly

Conclusion

  • Msdasql (Provider OLE DB Microsoft for ODBC) doesn't work well with date and some other type .net
  • System.Data.Odbc (.NET Framework Data Provider for ODBC) works perfectly

Final question

Is possible to use NET Framework Data Provider for ODBC in linked server? (can't find any documentation)

If not: is there any kind of connector (odbc based) that I can try to use in linked server as an alternative to msdasql?

Note Casting every single date colum using a case statement is not a solution for me. I'm searching for a global fix.

I also need to Write into this tables.

My more comfortable alternative in this case is use c#.

Thank you for your time

0

There are 0 best solutions below