Welcome! Log In Create A New Profile

Advanced

SQL Server + SQLconnect + Insert

Posted by Nathalie.pcs.crosspost 
Nathalie.pcs.crosspost
SQL Server + SQLconnect + Insert
September 01, 2008 05:52PM
Hello!!!

I'm having a weird problem using SQLconnet with sqlnative access.

The point is:
I have a table with a trigger that returns the id inserted.

If i do an insert in the table using a odbc connection everything works ok.
If i do an insert in the table using sqlconnect and access native to connect the sql returns the id but it inserts two lines in the database!!!!! And the id returned is always the second line inserted.


Does anybody knows why???

Message forwarded from pcsoft.us.windev
Marc De Swert
Re: SQL Server + SQLconnect + Insert
September 02, 2008 08:06AM
Yo Nathalie,

How do your insert code like?

Did you write an loop?


I use sqlconnect with native acces and have no problem.

Marc. :cool:
Nathalie
Re: SQL Server + SQLconnect + Insert
September 03, 2008 10:07PM
Hello Marc!!!!

Well its not a loop to do the insert.

I do like this:

IF sqlconnect() then
SQLexec("INSERT ...")
SQLclose()
END

Its very simple. But the weird is that the table in the SQL server with the trigger is saving two lines with only one INSERT
:confused:



How do you use the SQLconnect with th native access... I mean which sintax do you usually use?


If you can help i will be glad!

Thank you!
Marc De Swert
Re: SQL Server + SQLconnect + Insert
September 04, 2008 09:02AM
for the connection:
in the analysis section:
set ConnectionNAme
set NativeDriverAcces
set ServerName
set DatabaseName
set UserName
set Pasword

the code, I use it on a different way like you,
but the differency that the statement is set in a string (l_SQLSTR),
and the executeQry is given a name ( "QRY1")
i have 3 connections at the same time open to different bases so i must change the connection

tray the way of executing like mine, always check for errorhandling.
Note: when you open the program with native acces then you have already a connection, so the sqlconnect() is not to use untill you close every time the connection, but normaly, starting the program you open a connection and use it untill the programm closed.

in the Initialization section of your program you have to connect then:
if not gp_ConnectGENESIS then...


FUNCTION gp_ConnectGENESIS()

g_ConNrToGenesis = SQLConnect(v_Server,v_UserGEN,v_PswGEN,v_BaseGEN)

IF g_ConNrToGenesis <> 0 THEN //sqlconnect ok(v_Server,v_Usergen,v_Pswgen,v_Basegen) <> 0 THEN
// The connection was established successfully
HourGlass(False)
RESULT True
ELSE
// The connection failed: displaying an explanatory message
SQLInfo()
Error("The connection to the data source" + v_Server + " , " + v_BaseGEN + " failed"+CR+ "Error code: " + SQL.Error +CR+ SQL.MesError)

SQLDisconnect()
HourGlass(False)
RESULT False
END


somewhere in the code:
SQLChangeConnection(g_ConNrToGenesis)

l_SQLStr = " INSERT INTO DienstManagers VALUES('" + ED_van + "','" + ED_Manager + "')"
IF SQLExec(l_SQLStr, "QRY1") THEN
SQLClose("QRY1")
lp_ClearFields()
lp_FillTable()
ELSE
SQLInfo("QRY1")
Info("SQL error :" + SQL.MesError)
END


Marc. :cool:

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: