Welcome! Log In Create A New Profile

Advanced

Connecting To MSSQL

Posted by Milton 
Milton
Connecting To MSSQL
March 27, 2008 04:17AM
Hi All,

I am connecting to an MSSQL databse via OLEODBC using the standard odbc driver. I seem to have a problem writing NULLS to fields in the SQL table, although NULLS are acceptable in the table. I get an odbc error when trying to insert a NULL value.

Has anyone else experienced this?

Thanks,

Milton
Ben
Re: Connecting To MSSQL
March 27, 2008 09:26AM
Hi Milton,

Personally I'll stay clear of ODBC. OLE DB is by far more stable to use with SQL Server.

Regards
Justin
Re: Connecting To MSSQL
March 27, 2008 02:05PM
Hi Milton

I never use ODBC. OLE DB works very reliably with SQL Server and performs well too. I've had no problems so far (using Windev/Webdev for a few months now.)

Regards

Justin
Milton
Re: Connecting To MSSQL
March 27, 2008 11:04PM
Thanks to those who replied - I have changed the connection to OLEDB and will use this from now on.

However, the problem still exists and I have had to set up a dummy entry in the SQL database to accomodate the problem. The code is shown below and what I would have liked to do is to set the tblElements.eleUomIDBuy to NULL if Form_ClonerQuery.eleUomIDBuy is NULL rather than having to set it as 19 which is the index number for the dummy entry.

IF Form_ClonerQuery.eleUomIDBuy>0 THEN
tblElements.eleUomIDBuy=Form_ClonerQuery.eleUomIDBuy
ELSE
tblElements.eleUomIDBuy=19
END

I will keep experimenting and thanks again for the input.

Milton
Ben
Re: Connecting To MSSQL
March 27, 2008 11:20PM
Hi again mate,

Could you post me the error message? Also, is the field in question indexed in any way?

Cheers
Milton
Re: Connecting To MSSQL
March 27, 2008 11:47PM
Hi Ben,

Yes, the field is indexed and is the database is a normalised database with tables indexed on a numeric (integer) ID field.

The error message relates to a foreign key error and is as shown here -

"Description = INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_tblElements_tblUnitsOfMeasures'. The conflict occurred in the database 'NewMKLSandbox' table 'tblUnitsOfMeasures' column 'uomID' "

The weird thing is that if I make a direct entry into the table via the software it will accept a blank uomID field in the table but if I try and do it via an INSERT it will not accept a blank or NULL field.

What I am actually doing is cloning an existing item in the database table and changing a few items before doing the insert. For example, I have a product called a B90 which has such additional attached data such as a unit of measure (UOM) and I want to make a copy of it and call it a B99.

Milton

Milton
RESOLUTION OF Re: Connecting To MSSQL
April 01, 2008 05:42AM
Hi All,

For those that may be interested I finally solved the problem I had, connecting to an MSSQL database and not being able to set a field as NULL without getting an error message.

It had to do with my code where I was setting the field=Null

What ended up working was the following -

IF FGCStyleVariantsQuery2.fgcOrgIDDefaultSupplier>0 THEN
TblFinishedGoodsCosts.fgcOrgIDDefaultSupplier=FGCStyleVariantsQuery2.fgcOrgIDDefaultSupplier
ELSE
TblFinishedGoodsCosts.fgcOrgIDDefaultSupplier..Null=True
END
HWrite etc.

Thanks for those who suggested I use OLEDB which I am now doing and it is much better.

Milton
Leo Voet
Re: RESOLUTION OF Re: Connecting To MSSQL
April 01, 2008 10:01AM
.../...
TblFinishedGoodsCosts.fgcOrgIDDefaultSupplier..Null = True
.../...

Thanks, that's new for me to.

Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: