Why does my stored procedure always think there is a value? - stored-procedures

I have an ASP.NET 2010 app hitting a SQL 2005 db. I am attempting to build a stored proc dynamically, depending on the values selected on a search screen. I have done this many times in previosu versions of .net & sql with no problem. However, now, my IF statement always always acts as though no data was passed in. I have debugged the app and am sure that data is being set. I should note that when I run the procedure directly, with or without data, the correct data is returned.
Here is the rather simple stored proc..
ALTER PROCEDURE get_cases_by_search_criteria
#vin as varchar(30) = null
AS
declare #sqlstr varchar(1000)
set #sqlstr = 'SELECT
[Case].CaseID,
[Case].VIN,
[Case].Make,
[Case].Model,
[Case].VehicleYear,
if #vin is not null and #vin <> ''
set #sqlstr = #sqlstr + ' and ' + ('[Case].VIN = ''' + convert(varchar,#vin) + '''')
exec(#sqlstr)
RETURN
And here is the code that calls the stored proc...
Public Function GetCases(ByVal oSearchCriteria As SearchCriteria) As List(Of BE.Case)
Dim lstCase As New List(Of BE.Case)
Dim oCase As BE.Case
Dim oProviderFactory As New ProviderFactory
Dim oConnection As DbConnection
Dim oReader As System.Data.IDataReader
Dim oFactory As DbProviderFactory
Dim oCmd As DbCommand
Dim param1 As System.Data.Common.DbParameter
Try
'call my class to get an instance of the DBProviderFactory class
oFactory = oProviderFactory.GetFactory
'call another class of mine. pass in the DBProviderFactory class which will create a non-provider-specific connection object
oConnection = oProviderFactory.GetProviderConnection(oFactory)
'non-specific create command
oCmd = oConnection.CreateCommand
'non-specific parameter
If oSearchCriteria.VIN.Length = 0 Then
param1 = oFactory.CreateParameter()
param1.ParameterName = "#vin"
param1.DbType = DbType.String
param1.Value = DBNull.Value
oCmd.Parameters.Add(param1)
Else
param1 = oFactory.CreateParameter()
param1.ParameterName = "#vin"
param1.DbType = DbType.String
param1.Value = oSearchCriteria.VIN
oCmd.Parameters.Add(param1)
End If
oCmd.CommandType = CommandType.StoredProcedure
oCmd.CommandText = "get_cases_by_search_criteria"
Using (oConnection)
oConnection.Open()
oReader = oCmd.ExecuteReader()
While oReader.Read
oCase = New BE.Case
'Case
If oReader("CaseID") IsNot System.DBNull.Value Then oCase.CaseID = oReader("CaseID")
If oReader("Make") IsNot System.DBNull.Value Then oCase.Make = oReader("Make")
If oReader("Model") IsNot System.DBNull.Value Then oCase.Model = oReader("Model")
If oReader("VehicleYear") IsNot System.DBNull.Value Then oCase.VehicleYear = oReader("VehicleYear")
If oReader("VIN") IsNot System.DBNull.Value Then oCase.VIN = oReader("VIN")
lstCase.Add(oCase)
End While
oConnection.Close()
End Using
Catch ex As Exception
Throw ex
End Try
Return lstCase
End Function

Related

Update error on a recordset ADODB with VB.net

I try-ing to update application but when debugging everything goes well. But updating the records is not working anymore.
The error I get is: System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
public Sub LoginRegistration()
Dim RSReturn As New ADODB.Recordset
Dim SQLString As String = "SELECT tbllogin.idtbllogin, tbllogin.Log_date, tbllogin.Log_user FROM tbllogin LIMIT 1;"
Try
RSReturn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
RSReturn.CursorType = ADODB.CursorTypeEnum.adOpenDynamic
RSReturn.LockType = ADODB.LockTypeEnum.adLockOptimistic
RSReturn.Open(SQLString, cn)
RSReturn.AddNew()
RSReturn.Fields.Item("Log_date").Value = Now()
RSReturn.Fields.Item("Log_user").Value = "Harold" 'Environment.UserName
RSReturn.Update()
Catch ex As Exception
MsgBox(ex.Message, ex.StackTrace)
Finally
RSReturn.Close()
RSReturn = Nothing
End Try
End Sub```

ADO adLockBatchOptimistic allows updates on modified records

I'm begging for help, since I'm too stupid.
What I do:
Open connection to Access DB
Download Table to a Recordset
Disconnect the RecordSet
Update a record
Update the same record in DB (by another user)
Connect RecordSet back to DB
UpdateBatch affected record
Yesterday it was throwing an error that the record has been modified in the meantime.
Today it's updating the record without any issues.
I would bet my arm I haven't changed anything...
I open the recordset with following settings (first set them, then open):
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
I beg everyone for help
Example Code:
Dim DB_FOLDER_PATH As String
Dim DB_FILE_NAME As String
Dim DB_FILE_PATH As String
Dim CONNECTION As ADODB.CONNECTION
Dim CONNECTION_STRING As String
Dim QUERY_STRING As String
Dim tmp_RS As ADODB.Recordset
Dim tmp_RS2 As ADODB.Recordset
DB_FOLDER_PATH = "\\XXXXX\userdata\XXXXX\home\Documents\Data Base\"
DB_FILE_NAME = "TEST"
DB_FILE_PATH = DB_FOLDER_PATH & DB_FILE_NAME & ".accdb"
Set CONNECTION = New ADODB.CONNECTION
CONNECTION_STRING = "Provider=Microsoft.ACE.OLEDB.12.0" & ";" & "Data Source=" & DB_FILE_PATH & ";" & "Persist Security Info=False"
CONNECTION.Open CONNECTION_STRING
QUERY_STRING = "SELECT" & " " & "*" & " FROM [" & "DATA" & "]" & ";"
Set tmp_RS = New ADODB.Recordset
With tmp_RS
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.Open QUERY_STRING, CONNECTION
.ActiveConnection = Nothing
End With
Set tmp_RS2 = New ADODB.Recordset
With tmp_RS2
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.Open QUERY_STRING, CONNECTION
.ActiveConnection = Nothing
End With
With tmp_RS
.Fields("FIELD_LONG_TEXT_PLAIN").Value = "ABC"
.Update
.ActiveConnection = CONNECTION
.UpdateBatch
End With
With tmp_RS2
.Fields("FIELD_LONG_TEXT_PLAIN").Value = "ZXC"
.Update
.ActiveConnection = CONNECTION
.UpdateBatch
End With
Best Regards,
Michal

Google Closure Compile REST Api suddenly Throws Error 405 "Method not allowed"

I've been using Closure as part of y application to compress Javascript for a while now, but just started getting an error 405 - Method not allowed
My code as below was working for a couple of years, but has now stopped.
NOTE: this is not called frequently, just when ever any changes are detected in the Javascript files in my application.
I get no further error information from the Closure app than this.
Obviously this code performs a POST operation. If I use the form found here https://closure-compiler.appspot.com/home, it works, but if I either browser to the URL or use my code I get Error 405, it's almost as if my code is trying a GET method... but it's not...
Any ideas?
Public Class Closure
Property OriginalCode As String
Property CompiledCode As String
Property Errors As ArrayList
Property Warnings As ArrayList
Property Statistics As Dictionary(Of String, Object)
Public Sub New(Input As String, Optional CompliationLevel As String = "SIMPLE_OPTIMIZATIONS")
Dim _HttpWebRequest As HttpWebRequest
Dim _Result As StringBuilder
Dim ClosureWebServiceURL As String = "http://closure-compiler.appspot.com/compile?"
Dim ClosureWebServicePOSTData As String = "output_format=json&output_info=compiled_code" &
"&output_info=warnings" &
"&output_info=errors" &
"&output_info=statistics" &
"&compilation_level=" & CompliationLevel & "" &
"&warning_level=default" &
"&js_code={0}"
'// Create the POST data
Dim Data = String.Format(ClosureWebServicePOSTData, HttpUtility.UrlEncode(Input))
_Result = New StringBuilder
_HttpWebRequest = DirectCast(WebRequest.Create(ClosureWebServiceURL), HttpWebRequest)
_HttpWebRequest.Method = "POST"
_HttpWebRequest.ContentType = "application/x-www-form-urlencoded"
'//Set the content length to the length of the data. This might need to change if you're using characters that take more than 256 bytes
_HttpWebRequest.ContentLength = Data.Length
'//Write the request stream
Using SW As New StreamWriter(_HttpWebRequest.GetRequestStream())
SW.Write(Data)
End Using
Try
Dim response As WebResponse = _HttpWebRequest.GetResponse()
Using responseStream As Stream = response.GetResponseStream
Dim encoding As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Using readStream As New StreamReader(responseStream, encoding)
Dim read(256) As Char
Dim count As Integer = readStream.Read(read, 0, 256)
While count > 0
Dim str As New String(read, 0, count)
_Result.Append(str)
count = readStream.Read(read, 0, 256)
End While
End Using
End Using
Dim js As New JavaScriptSerializer
js.MaxJsonLength = Int32.MaxValue
Dim d As Dictionary(Of String, Object) = js.Deserialize(Of Dictionary(Of String, Object))(_Result.ToString())
Me.CompiledCode = d.NullKey("compiledCode")
Me.Warnings = TryCast(d.NullKey("warnings"), ArrayList)
Me.Errors = TryCast(d.NullKey("errors"), ArrayList)
Me.Statistics = TryCast(d.NullKey("statistics"), Dictionary(Of String, Object))
Catch ex As Exception
Me.CompiledCode = ""
If Me.Errors Is Nothing Then
Dim er As New List(Of String)
er.Add(ex.ToString())
Me.Errors = New ArrayList(er)
Else
Me.Errors.Add(ex.ToString())
End If
End Try
Me.OriginalCode = Input
End Sub
End Class
Closure REST api is redirecting to https, you may want to try to POST to "https://closure-compiler.appspot.com/compile" directly in order to avoid redirection.

Open popup conditional from controler MVC And Retrieve the answer

I want from my controller open a poup-up that contains data and ask a question to the user. According to his answer, I continue or stop treatment.
Function Traitement(model As TraitementViewModel, confirm_value As String) As ActionResult
Try
If (ModelState.IsValid) Then
Dim exception As Exception = Nothing
Dim mois As Integer = Mid(model.dateTraitement, 4, 2)
Dim annee As Integer = Right(model.dateTraitement, 4)
Session("mois") = mois
Session("annee") = annee
Dim extract As Extraction = New Extraction()
Dim result As Integer = extract.Recherche(mois, annee).Rows.Count()
If (result <> 0) Then
OPEN POPUP
Artciles Montant
1 100
2 200
Do you want continue
YES NO
IF(confirm_value = "yes") Then
continue...
Else
Exit Function
Else
continue...
End If
End If
End Function

Classic ASP - ADO execute Stored Procedure passing in parameters

I am needing to pass parameters into a stored procedure with Classic ASP. I do see some people using the Command object and others NOT using it.
My sproc params are like this:
#RECORD_NUMBER decimal(18,0),
#ErrorType nvarchar(100),
#INSURANCE_CODE smallint,
#CompanyId int,
#INS_ID_NUM nchar(22)
Then I'm trying to do this:
Dim conn, rsSet,rsString, cmd
Dim RN,ET,IC,CI,IIN
RN = Request.Form("Record_Number")
ET = Request.Form("ErrorType")
IC = Request.Form("INSURANCE_CODE")
CI = Request.Form("CompanyID")
IIN = Request.Form("INS_ID_NUM")
set conn = server.CreateObject("adodb.connection")
set rsSet = Server.CreateObject ("ADODB.Recordset")
conn.Open Application("conMestamed_Utilities_ConnectionString")
rs_string = "apUpdateBill " & RN &",'" & ET & "'," & IC & "," & CI & ",'" & IIN & "'"
rsSet.Open rsString, conn, adOpenForwardOnly,, adCmdText
(I don't need a Recordset, i'm just trying to get it to send in data)
Error:
ADODB.Recordset error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
I have tried Command stuff and I get "precision" errors
Do I "have" to use command object?
e.g.
Set cmd = Server.CreateObject("ADODB.Command")
'Set cmd.ActiveConnection = conn
'cmd.CommandText = "apUpdateBill"
'cmd.CommandType = adCmdStoredProc
'Cmd.Parameters.append Cmd.createParameter("#Record_Number", adDecimal, adParamInput, 18)
'Cmd.Parameters("#Record_Number").Precision = 0
'Cmd.Parameters("#Record_Number").value = Request.Form("Record_Number")
Here is how you would do it, you won't need to create a recordset object since it is an update stored procedure:
'Set the connection
'...............
'Set the command
DIM cmd
SET cmd = Server.CreateObject("ADODB.Command")
SET cmd.ActiveConnection = Conn
'Prepare the stored procedure
cmd.CommandText = "apUpdateBill"
cmd.CommandType = 4 'adCmdStoredProc
cmd.Parameters("#RECORD_NUMBER") = Request.Form("Record_Number")
cmd.Parameters("#ErrorType") = Request.Form("ErrorType")
cmd.Parameters("#INSURANCE_CODE") = Request.Form("INSURANCE_CODE")
cmd.Parameters("#CompanyId") = Request.Form("CompanyID")
cmd.Parameters("#INS_ID_NUM") = Request.Form("INS_ID_NUM")
'Execute the stored procedure
'This returns recordset but you dont need it
cmd.Execute
Conn.Close
SET Conn = Nothing

Resources