If there are any ACE/VS.Net gurus looking here, I posted an issue in the wrong thread
Any help would be awesome!!
I'll continue here.
1: Looking at the logs, there's a few things going on. One that seems to be an issue is this:
Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
I did make reference to threading a while back, but realized I didn't need this, removed all references I could find, but the issue persists in the log file and Calc will not run. Tests fine in the ACE test tool of the .net plugin. Also, I seems to be fine running the Recalculate feature. Not sure what the difference is. I've set all compiles to target x86 and am using .NET Framework 2.0 (Haven't needed to change it yet.
2. here is already an open DataReader associated with this Command which must be closed first.
Different script, but this one is odd. I have queries going in and out of a side SQL server. I'm sure I'm closing all the connections
I do however have
Right under Public Class
Dim conn As New Data.SqlClient.SqlConnection() Dim sqlCommand As New Data.SqlClient.SqlCommand()
to make the conn available throughout
SO that I don't open this everytime we execute, trying to keep things running a little faster
conn.Close() conn = Nothing
Perhaps I have this set up incorrectly?
I am not sure if you need to use Module dependent initialization or termination for your purpose. With the few information it is difficult to say where your code may fail. I haven't yet retrieved data from a SQL Server from within an ACE calculation but know others have done this. I'll try to come up with an easy example for your reference.
As suggested earlier already, try starting as simple as possible and increase complexity over time and use Try-catch. If you have a better idea as where your code is failing you may want to post that snippet. You can also post the content of the entire .vb file.
Here's the project if you'd like to have a look
The reference DLLs are not included as these are licensed and I can't really release them
I have created a simple example that uses CDT158 as calculation trigger, reads some data from a SQL table and writes the data to a PI Tag. I was lazy and used data type String for the PI Tag. The used query retrieves the rowset with the most recent date. The ACE module is running without any issues in my test environment.
As a hint, I have started coding a console application which allows me to better control and debug. After the console application was running, I copied the code over and did some minor required modifications e.g. removing Console.WriteLine() occurrences.
Public Class Mar2714cl
Private mar2714 As PIACEPoint
Private cdt158 As PIACEPoint
' Tag Name/VB Variable Name Correspondence Table
' Tag Name VB Variable Name
' cdt158 cdt158
' mar2714 mar2714
Public Overrides Sub ACECalculations()
Dim cn As New SqlConnection()
Dim ds As New DataSet()
Dim da As SqlDataAdapter
Dim dr As DataRow
Dim sTim As String
Dim sVal As String
Dim sStat As String
Dim sRes As String
cn.ConnectionString = "Server=tcp:MYPISERVER\SQLEXPRESS; Async=false; Database=MyDB; User ID=sa; Password=IwontTellYou"
da = New SqlDataAdapter("SELECT TOP 1 [Time],[Value],[Status] FROM [MyDB].[dbo].[TimeSeries] ORDER BY [Time] DESC", cn)
dr = ds.Tables(0).Rows(0)
sTim = dr.Item("Time").ToString()
sVal = dr.Item("Value").ToString()
sStat = dr.Item("Status").ToString()
sRes = "Value " + sVal.ToString + " at " + sTim + " has Status " + sStat
mar2714.Value = sRes
Catch ex As Exception
LogPIACEMessage(OSIsoft.PI.ACE.MessageLevel.mlErrors, ex.Message, Me.Name)
Protected Overrides Sub InitializePIACEPoints()
cdt158 = GetPIACEPoint("cdt158")
mar2714 = GetPIACEPoint("mar2714")
' User-written module dependent initialization code
Protected Overrides Sub ModuleDependentInitialization()
' User-written module dependent termination code
Protected Overrides Sub ModuleDependentTermination()
You initially created the other thread at PI SDK Development forum and later this thread at PI ACE Development. Please note that threads can be moved by either forum administrators or the author. You should see a "Moderate" link below the very first post which beside other actions allows to move a thread from one forum to another. When moving a thread to another forum, links will continue to work.
I will also update the other thread with an information about the cross reference. Please consider both threads resolved and open a new one in case you are running into additional issues or have another question.
Retrieving data ...