@@IDENTITY detection with ADO
-
Is there a way to detect if a specific DB can support @@IDENTITY ? Problem is, its possible to change my connection string depending on the database i want to connect to, as a client choice. But not all DB systems make use of @@IDENTITY. My tests here are with MSAccess and MSDE and both support it. I'm using ADO from C++ in VC 2003. Thx for any replies, even if negative.
-
Is there a way to detect if a specific DB can support @@IDENTITY ? Problem is, its possible to change my connection string depending on the database i want to connect to, as a client choice. But not all DB systems make use of @@IDENTITY. My tests here are with MSAccess and MSDE and both support it. I'm using ADO from C++ in VC 2003. Thx for any replies, even if negative.
Although I must admit I don't have first-hand experience with anything but Access or MSDE, you could simply create a test function where you execute an insert and catch any exceptions your SELECT @@IDENTITY throws. If there's no exception thrown (and you receive a meaningful result) then @@IDENTITY should work later on as well... Or: Do not rely on a DB supplying such an information in a certain way but create a stored procedure to perform your inserts and let the procedure return the ID of the newly created element. That way you might be more flexible than hard-coding it in your program. Regards, mav