Error code 3146 odbc call failed - using Cimplicity Even Scheduler - proficy

I have written this below script. When i ran this script in the script editor its working fine and inserting row into the table. But when I tried to use Even scheduler to run this script for every 1min that time I am getting "Error code 3146".
Sub Main()
Dim s As String
Dim qry As Long
id& = SQLOpen("dsn=TestSOADB",s$,3)
qry = SQLExecQuery(id&,"insert into test2 values('FromCimplicity2','1123')")
'MsgBox "There are " & qry & " columns in the result set."
id& = SQLClose(id&)
End Sub

Related

VBA could find R library

I am trying to use EXCEL as the front end for a R script. So far, I tested my R script in Windows CMD but I could not make it work in VBA. The error message is Error in library(readxl) : there is no package called 'readxl'. So it looks like VBA environment is picky.
Any suggestions on fixing this error? (fixed now)
Is there a way to run R script and save the function returned value (now it is 5) into a variable in VBA? I can do this by saving a text file and load again, but not sure if there is a better way to handle this.
a simple example of R script, which defines a function and calls it later.
est_var_dw <- function(){
library(readxl)
library(minpack.lm)
library(msm)
return(2+3)
}
est_var_dw()
a simple example of VBA
Sub run_r()
Dim shell As Object
Set shell = VBA.CreateObject("WScript.Shell")
Dim waitTillComplete As Boolean: waitTillComplete = True
Dim style As Integer: style = 1
Dim errorCode As Integer
Dim path As String
path = """" & Cells.Range("B1") & """ """ & Cells.Range("B2") & """ & Pause"
errorCode = shell.Run(path, style, waitTillComplete)
End Sub
Update
I figured out the first issue was due locations of different R packages, which can be solved by using .libpath
.libPaths(c(R_library_pth1, R_library_pth2))
There is a very good function for the second part of your question here: Capture output value from a shell command in VBA?
bburns-km defines a vba function ShellRun:
Public Function ShellRun(sCmd As String) As String
'Run a shell command, returning the output as a string'
Dim oShell As Object
Set oShell = CreateObject("WScript.Shell")
'run command'
Dim oExec As Object
Dim oOutput As Object
Set oExec = oShell.Exec(sCmd)
Set oOutput = oExec.StdOut
'handle the results as they are written to and read from the StdOut object'
Dim s As String
Dim sLine As String
While Not oOutput.AtEndOfStream
sLine = oOutput.ReadLine
If sLine <> "" Then s = s & sLine & vbCrLf
Wend
ShellRun = s
End Function
As long as RScript.exe is in your PATH, you can then call from VBA:
Sub Test()
Dim ScriptPath As String
Dim StringOut As String
ScriptPath = "C:\...\test.R" 'Your Path Here
'Assign
StringOut = ShellRun("RScript " & ScriptPath)
'Print
Debug.Print StringOut
End Sub
Anything that your R script prints to console during session will be returned to VBA as a string

Execute PL/SQL procedure from vb6 on Oracle 11g

I am trying to call a PL/SQL procedure which has an output value from a Visual Basic 6 function, but it does not work.
Here my code.
PL/SQL code (so far, it is just a mock):
create or replace
PROCEDURE IS_SINISTRO_ABS_MOCK
( numPol in VARCHAR2,
codGaranzia in VARCHAR2,
res out BOOLEAN
) AS
BEGIN
res := TRUE;
END IS_SINISTRO_ABS_MOCK;
VB6 code:
Private Function IsSinistroInABS(NumPol As String, CodGaranzia As String) As Boolean
Dim dbConn As New ADODB.Connection
With dbConn
.Provider = "OraOLEDB.Oracle"
.Properties("Data Source") = "*********"
.Properties("User Id") = "ROUTING"
.Properties("Password") = "***********"
.Open
End With
Dim dbCmd As ADODB.Command
Dim result As Boolean
Set dbCmd = New ADODB.Command
dbCmd.ActiveConnection = dbConn
dbCmd.CommandTimeout = 300
dbCmd.CommandType = adCmdStoredProc
dbCmd.CommandText = "{CALL ROUTING.IS_SINISTRO_ABS_MOCK(?,?,?)}"
dbCmd.Parameters.Append dbCmd.CreateParameter(, adLongVarChar, adParamInput, _
Len(NumPol), NumPol)
dbCmd.Parameters.Append dbCmd.CreateParameter(, adLongVarChar, adParamInput, _
Len(CodGaranzia), CodGaranzia)
dbCmd.Parameters.Append dbCmd.CreateParameter(, adBoolean, adParamOutput, , _
result)
dbCmd.Prepared = True
dbCmd.Execute
IsSinistroInABS = dbCmd.Parameters("res").value
dbConn.Close
End Function
The DB connection works properly, indeed I succeeded in executing a standard SQL query, but I get an unspecified error when I try to run the procedure. I succeeded also in launching a procedure without any parameters. As a result, the problem is supposed to be in the use of them.
Note that the procedure is a standalone one. In other words, it is not included in any package.
Maybe I'm a bit late (you posted your question 2.5 years ago), but I got the same problem.
After a lot of digging and frustration, I found out the error occurs when the stored procedure has numeric output parameters (VARCHAR is OK as well as any input parameter).
I finally found out that everything works correctly when you use the ancient DB-provider MSDAORA.1.

Asp.net string creation gives operator "&" error VB

I have a SQL string in Asp.net web page, with vb code behind.
It was working fine before but for unknown reason I start now getting the following error:
Error: Sys.WebForms.PageRequestManagerServerErrorException: Operator '&' is not defined for string "UPDATE db.usersdata SET `SH" and type 'TextBox'.
UPDATE: SH is a string ('SAVE' or 'HIDE')
UPDATE: I am using MySQL database on the background.
Protected Sub savehide_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim SQLstring As String = ""
Dim SH As String
SH = saveorhide.SelectedItem.Value
' the following line is where the error occurs
SQLstring = "UPDATE `db`.`usersdata` SET `SH`='" & SH & "' WHERE `PIC` = '" & Session("UserId") & "'"
Session("SH") = SH
SQLNonQuery_mysql(SQLstring)
CLEARALL()
displaydata()
End Sub
I have spent hours but I cannot find the reason for this, specially when before it was working fine.
This code runs when a dropdownlist field is changed.
The thing it also started to happen to other dropdownlist and SQL string creation code...So it is failing in various VB places now (as I said before it wasn't)
I am wondering if there is a bug or some weird reason why this error is coming out now (and not before) and what would be the solution.
According to the error message, either SH is a TextBox or Session("UserId") is a TextBox.
Since you already showed the declaration of SH, the only suspect remaining is the Session("UserId").
Can you show how you are setting the Session("UserId") value?
My best guess is that you are doing this:
Session("UserId") = TextBox1
you should change it to:
Session("UserId") = TextBox1.Text
(replace TextBox1 with name of your TextBox)

Asp.net: Excel file uploading does not finish but gives no error message

I'm having a rather weird problem trying to upload an Excel file and storing it in a SQL server table in an ASP.net App.
The file is not too big: about 2.5 or 3 Mb.
The problem is that the upload gets "interrupted" after loading some rows, appearently without causing any specific error, since the load process finishes by showing a success message that I'm sending to the client:
"The process finished successfuly: XXX rows were uploaded from the
file".
The problem is that the XXX rows are not all the rows from the file. Depending on how much information there is in each column of the Excel file, the process is only uploading, for instance, 15500 rows from a total of 25000 that the file has. (If there's less information in the Excel file, it can upload, lets say 20000 of the 25000 rows that it may have)... the fact is that the file is not being "completely" uploaded.
I already tried increasing the "httprequest-maxRequestLength" value in the web.config, even though the file is not bigger than the default 4Mb file upload that ASP.net has.
The code (vb.net) that I'm using upload and read the file is, basically, this:
Dim connection As DbConnection = Nothing
Dim Command As DbCommand = Nothing
Dim ConexionStringExcel As String
Dim dr As DbDataReader
Dim mensajeError as String = ""
Dim ncAdic as Integer = 0
Dim nReg as Integer = 0
'String connection for Excel 2007: for now, I'm not allowing other Excel versions
ConexionStringExcel = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source = " & sNombreArch & ";" & _
"Extended Properties=Excel 12.0 Xml;"
'sNombreArch is the full name of the uploaded file
connection = New OleDb.OleDbConnection(ConexionStringExcel)
Command = connection.CreateCommand()
Command.CommandText = "SELECT * FROM [" + nomHojaArch + "$]"
'---
'lblMensaje is a Label object in the aspx page:
'---
lblMensaje.Visible = False
Try
'Open the Excel file
connection.Open()
'Read file content
dr = Command.ExecuteReader()
While dr.Read
Try
'Two first columns of the file are mandatory in my case...
If Not IsDBNull(dr(0)) And Not IsDBNull(dr(1)) Then
'---
'dsTempCargue is a SqlDataSource object in the aspx page
'---
dsTempCargue.InsertParameters.Item("idReg").DefaultValue = dr(0)
dsTempCargue.InsertParameters.Item("nombre").DefaultValue = dr(1)
For ncAdic = 2 To 10
If Not IsDBNull(dr(ncAdic)) Then
dsTempCargue.InsertParameters.Item(ncAdic).DefaultValue = dr(ncAdic)
Else
dsTempCargue.InsertParameters.Item(ncAdic).DefaultValue = DBNull.ToString
End if
Next
dsTempCargue.Insert()
nReg = nReg + 1
Else
mensajeError = "Column A and B of the File cannot be empty"
Exit While
End If
Catch exRead As Exception
mensajeError = "Error reading the file or saving its content: " & exRead.Message
Exit While
End Try
End While
'If there was no error, show success message
If String.IsNullOrEmpty(mensajeError) Then
mensajeError = "The process finished successfuly. " & nReg.ToString() & " rows were uploaded from the file"
End IF
Catch ex As Exception
mensajeError = "Error uploading the file: " & ex.Message
End Try
lblMensaje.Text = mensajeError
lblMensaje.Visible = True
Why do you think this uploading process is failing to read the entire file???... Any advice will be appreciated.
Thanks a lot,
Diego
For the tables that you are storing the rows in, what datatype are the various columns? Perhaps the content of one of the cells is incompatible with the column datatype. Do you have any way of checking?
Even though I'm really not sure about what could have been the cause of the error, I finally managed to get it working by changing my code to use a Third-party library that I found and that had some good comments, which is available here:
http://exceldatareader.codeplex.com/
I'm not really sure about what the original problem was and why using this library solved the issue, but It worked. (Perhaps when I have some time I'll try to find more info about this problem I had)
Thanks Patrick for your comments and all for the interest

Getting "Operation is not valid due to the current state of the object" error for Exchange commands

I have an ASP.NET 3.5 application running Powershell scripts to add/update Exchange mailboxes. Most of the Powershell commands work great, but two of them so far have caused an error: get-calendarprocessing and set-calendarprocessing, which get or set users assigned to schedule a Room. The error is System.Management.Automation.CmdletInvocationException: Operation is not valid due to the current state of the object. When I run the commands from the Exchange Management Shell, they work fine. We have patched and rebooted the Exchange server.
Command example:
get-calendarprocessing Room.1 | select -expand bookinpolicy (or similar variations)
Private Function RunScript(ByVal ScriptFileName As String, ByVal Arguments() As String) As Collection(Of PSObject)
Dim sb As New StringBuilder
Dim strScript As String
' create Powershell runspace and open
If psRunspace Is Nothing Then
psRunspace = InitializeRunspace()
End If
'Grab Powershell script from text (.ps1) file
strScript = File.ReadAllText(ScriptFileName)
'inject the arguments into the script
strScript = InsertArguments(strScript, Arguments)
Logging.LogMessage(strScript)
'Open the runspace and create a pipeline if it's not already open
If psRunspace.RunspaceStateInfo.State = RunspaceState.BeforeOpen Then
psRunspace.Open()
End If
Dim MyPipeline As Pipeline = psRunspace.CreatePipeline()
MyPipeline.Commands.AddScript(strScript)
Try
Dim psResults As Collection(Of PSObject)
psResults = MyPipeline.Invoke() 'ERRORS HERE
Return psResults
Catch ex As Exception
Logging.LogMessage(ex.Message)
Throw ex
End Try
End Function

Resources