Problem with logging set


Alex

Recommended Posts

Hello everyone. This is my first time working with DAQFactory (DAQFactory Pro Trial 20.5), which is installed on a Windows 10 Enterprise virtual machine. I have been doing logging tests on a SQL database via ODBC.
To do this I have proceeded as follows:
- I have created a channel, name "Pressure" type "A to D", device type "Test", which varies every 10 seconds.
- I have a SQL server on another Windows 10 Pro virtual machine, in which I have created an empty database called "prueba".
- In the DAQFactory virtual machine I have created an ODBC connection to access the "prueba" database, this connection works fine.
- I have created a logging set for the value of the Pressure channel, following the advice seen in other topics.

When starting the logging set I see the following messages:
C1012 Failed to access table for logging. Msg: Incorrect syntax near '14'. (appears once)
C1011 Could not create table for logging. Msg: There is already an object named 'PRESSVALUE' in the database. (appears every 10 seconds).

In the database, the table "PRESSVALUE" has been automatically created, but it remains empty.

I have tried several times, changing the value of the sql string "String", but without success.

Please if anyone has any idea to solve the problem. Thanks.

Alex

LOGGINGSET.png

ODBCCONNECTION.png

DATABASE.png

Link to comment
Share on other sites

I personally do not like to use the logging set for ODBC for several reasons, all related to my desire for control:

1) you have no control over the table schema 

2) you have no control over the error handling, nor do you get much detail on what caused the error

You are running into the second issue.  For this reason I would recommend just writing a basic script.  It is quite simple.  First in a StartUp sequence marked autostart, open the database:

global dbase = db.open("prueba")

Then create a sequence for logging.  Something like:

while(1)
   private string sql = "INSERT INTO PressValue (TheTime, Pressure) Values ("
   sql += formatSQLDate(getTime(pressure[0]))
   sql += "," + pressure[0]
   sql += ");"
   db.execute(dbase, sql)
   delay(10)
endwhile

You'll also need a sequence called formatSQLDate with this script:

   function FormatSQLDate(date)
      if (isempty(date))
         private date = systime()
         ? "Date not provided"
      endif
      return(formatDateTime("'%Y-%m-%d %H:%M:%S",date) + Right(format("%.3f",date),4) + "'")

I didn't add error handling, but you can add try/catch blocks as needed.  You might add a ? sql line right before the db.execute() so you can see what your sql command is.  If it then has problems, you can test that exact line in your SQL server tool.
 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.