I am having a weird problem with calling a SQL Stored Procedure from VB.
I have created a stored procedure on SQL. Code snippet as follows:
ALTER PROCEDURE [dbo].[PE0010_InsertDPW]
@DailyWashCycle AS INT,
@PumpNo AS INT,
@WashDurationSecs AS INT,
@Result AS INT OUTPUT
AS
BEGIN
SET @Result= 1
--All other code commented out
END
On the VB side, I have created a link to SQL and data set with this stored procedure in it. The actual VB code that calls the stored procedure is as follows:
Dim DailyCycle As Integer = 0
Dim PumpNo As Integer = 0
Dim Duration As Integer = 0
Dim res As Integer = 0
Dim DBQueries As New dsProcessDBTableAdapters.QueriesTableAdapter
DBQueries.PE0010_InsertDPW(DailyCycle, PumpNo, Duration, res)
I get the following message:
An unhandled exception of type 'System.AccessViolationException' occurred in Data Systems Manager.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
However, if I comment out any variable other than @Result on SQL and update the stored procedure on VB and run it with 3 variables then it works fine.
The SQL procedure works fine if I execute it form SQL with all 4 variables so there must be something wrong with my link or something. I have tried changing the .NET Framework Data Provider to OLE DB from SQL Server when creating the link. Same problem occurs. Tried closing everything and opening it again. No difference.
Has anyone had the same problem? I'm completely out of ideas now.
PC: Intel Core i5-3550 CPU @3.30GHz, 12GB RAM
Okay, I've figured out how to fix the issue but I still don't know why it was giving me so much trouble.
I compiled my project for .NET Framework 4 for compatibility with all our systems here at my work. This has never been an issue in the past but even new projects broke in the same way when I chose .NET 4. I had to install .NET Framework 4.5.2 (KB2901907) and everything just worked again after the system restart following that. Even for this project targeting .NET 4 (No other changes made). Weird, because a system restart was the first thing I tried. Seems like some kind of .NET Framework issue.