Re: Different empty_string/NULL handling under ODBC and OLE DB?



sepe (sebastian.peters@xxxxxxxxx) writes:
I've a problem with SQL Server and OLE DB. SQL Server handles NULL as
NULL whereas empty string is stored as a space. This is correct when
using OLE DB but with ODBC an empty string gets converted to NULL with
SQL Server.

When migrating from ODBC to OLE DB we get errors when inserting an
empty string into foreign key columns. Therefore I guess that ODBC
drivers implicitly convert empty string to NULL. Does anyone know if
there is any parameter to set this behaviour for OLE DB connections?

Example:
CREATE TABLE foo (id VARCHAR(25) PRIMARY KEY, data VARCHAR(10))
CREATE TABLE bar (id VARCHAR(25) PRIMARY KEY, foo_id VARCHAR(25)
CONSTRAINT foo_id FOREIGN KEY(foo_id) REFERENCES foo(id) ON DELETE
CASCADE)
INSERT INTO foo VALUES ('1', 'data')
INSERT INTO bar VALUES ('1', '1')
INSERT INTO bar VALUES ('2', null)
-- possible with ODBC connect, error with OLE DB (b/c no conversion)
INSERT INTO bar VALUES ('3', '')

I'm working with legacy code under Gupta/Unify Team Developer and need
to migrate from ODBC to OLE DB, without changing all INSERTs from
empty string to NULL.

I don't know what your code looks like, but if your code looks like
the above, and some driver or tool changes '' to NULL, bad things are
going on.

Now, I would guess that the real code looks different, and it could
help to see it. Maybe. I suspect that the answer lies within Gupta of
which I know nothing.


--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

.



Relevant Pages

  • Re: Samplclnt example in MDAC 2.8: My Story
    ... It's funny how Microsoft appears to be pushing OLE DB hard, ... > people seem reluctant to abandon ODBC, and again, I've heard from ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (microsoft.public.data.oledb)
  • Re: What is the faster way to insert/buck insert rows into SQL Server
    ... I would have said SqlClient would be the fastest--that or DBLib. ... Hitchhiker's Guide to Visual Studio and SQL Server ... code in C++ and used ODBC driver SQLBindParameter to bind the data in the ... OLE DB .Net ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Q: what is the relation between DB-Lib, OLE-DB, and ODBC?
    ... >> I had reason some time ago to make a choice between ODBC and OLE DB ... can you recommend any sources of decent sample code for this (OLE ... > DB with MS Sql server), and also, while we're here, on writing extended ...
    (microsoft.public.data.oledb)
  • Problem with odbc and Sql Server
    ... I have found a problem using MS Sql Server connecting via the odbc ... If I execute the command without using parameters - ... column to an empty string resulted in it being set to a single space. ...
    (comp.lang.python)
  • Re: MS Access and ODBC/OLE DB
    ... The MS Access SQL Server Database Wizard attempts to create a database ... If it uses OLE DB, is there a need to confure OLE DB? ... >ODBC and ADO support sending T-SQL commands to SQL Server to perform ...
    (microsoft.public.sqlserver.odbc)