SQLite v1.0.115 vs v1.0.116 - vb.net

I am having problems upgrading SQLite from v1.0.115 to v1.0.116 in Visual Studio 2022 with VB.Net, Debug, Any CPU.
To test this, I made two identical test-projects. In one I installed System.Data.SQLite v1.0.115 via the NuGet Package Manager. In the other I installed v1.0.116 in the same way.
In v1.0.115 the following line is fine:
conn.LoadExtension("SQLite.Interop.dll", "sqlite3_json_init")
but in v1.0.116 I get an error for that line: The specified procedure could not be found.
I did see a post that suggested adding the full path to the Interop file, so I tried:
conn.LoadExtension(Application.StartupPath() & "\bin\Debug\x86\SQLite.Interop.dll", "sqlite3_json_init")
but this gives an error for that line: The specified module could not be found.
For reference, my full function is:
Public Function Connect(ByVal DBnum As Integer) As SQLiteConnection
Dim conn As New SQLiteConnection
Dim DBpath As String = Application.StartupPath() & "\hamdata.db3"
Try
conn = New SQLiteConnection("Data Source=" & DBpath & ";Version=3;")
If conn.State = ConnectionState.Closed Then
conn.Open()
conn.EnableExtensions(True)
conn.LoadExtension("SQLite.Interop.dll", "sqlite3_json_init")
End If
Catch ex As Exception
Debug.WriteLine(vbCrLf & "Message:" & vbCrLf & ex.Message)
Debug.WriteLine(vbCrLf & "Source:" & vbCrLf & ex.Source)
Debug.WriteLine(vbCrLf & "StackTrace:" & vbCrLf & ex.StackTrace)
Debug.WriteLine(vbCrLf & "TargetSite:" & vbCrLf & ex.TargetSite.ToString())
MsgBox("Connection to Database " & DBnum & " at '" & DBpath & "' has Failed! Message: " & ex.Message)
End Try
Return conn
End Function

The 'Path.Combine' didn't work at all, for some reason!
Debug.WriteLine(Path.Combine(Application.StartupPath, "\bin\Debug\x86\SQLite.Interop.dll"))
returned: \bin\Debug\x86\SQLite.Interop.dll
Debug.WriteLine(Application.StartupPath)
returned: C:\Programming\SQLite\SQLite_v1.0.116_TestBed\bin\Debug
Debug.WriteLine(Application.StartupPath & "\bin\Debug\x86\SQLite.Interop.dll")
returned: C:\Programming\SQLite\SQLite_v1.0.116_TestBed\bin\Debug\bin\Debug\x86\SQLite.Interop.dll
Both of the following lines:
conn.LoadExtension(Path.Combine(Application.StartupPath, "\bin\Debug\x86\SQLite.Interop.dll"), "sqlite3_json_init")
conn.LoadExtension(Application.StartupPath & "\bin\Debug\x86\SQLite.Interop.dll", "sqlite3_json_init")
returned the error: 'The specified module could not be found.'
so I feel that the path-changes are a red-herring. As mentioned before,
conn.LoadExtension("SQLite.Interop.dll", "sqlite3_json_init")
returns the error: 'The specified procedure could not be found.'
which might indicate that the file 'SQLite.Interop.dll' has been found, but the internal procedure was not.
Following a suggestion in another post, I then deleted both the 'x64' and 'x86' folders in the Debug folder, and then did a 'Build'. The folders and their 'SQLite.Interop.dll' files were replaced, but the 'The specified procedure could not be found.' error continued, so I am no further forward!
SUCCESS
It appears that the problem is to do with the extension's entry point, for which I was using "sqlite3_json_init". The documentation says you can leave this argument blank and the extension loader logic will attempt to figure out the entry point on its own, but when I tried it I just got the 'The specified procedure could not be found.' error again. After some more searching, I found someone mentioning the entry point "sqlite3_fts5_init". I tried this in the line:
conn.LoadExtension("SQLite.Interop.dll", "sqlite3_fts5_init")
and everything seems to be working again!

Related

Unhandled Exception of Type System.Data.SqlClient SQL Exception in System.Data.dll

I am attempting to code a little Customer/sales database in VB. However on compiling I am getting the error stated in the subject. Apparently there is no connection to the database posible.
Here is the code I got so far:
Public Class Principal
Using Connect As SqlConnection =
Friend Sub CreateDatabase()
New SqlConnection("Data Source=(local);" &
"Integrated Security='SSPI';")
Dim strCreateDatabase As String = "IF EXISTS ( " &
"SELECT name " &
"FROM sys.databases " &
"WHERE name = N'BMSTIDB'" &
" ) " &
"DROP DATABASE BMSTIDB; " &
"CREATE DATABASE BMSTIDB"
Dim Command As SqlCommand =
New SqlCommand(strCreateDatabase, Connect)
Connect.Open()
Connect.ExecuteNonQuery()
MsgBox("A Database with the name of " &
"BMSTIDB has been created. ")
End Using
It compiles fine and it doens't display any errors or issues. However as mentioned above it does give the error upon running, when it first attempts to connect to the DB.
I am using Visual Studio 2015 Enterprise and Community.
Thanks a lot,
BenjB
New SqlConnection("Data Source=(local);" &
"Integrated Security='SSPI';Database=master")
You're missing a closing single quote here:
"WHERE name = N'BMSTIDB" &
It should be:
"WHERE name = N'BMSTIDB'" &
Once you fix that you'll find you're also missing the BEGIN and END keywords.

How to read an excel while in use by another user with Oledb?

I have an excel on a shared drive and my application is using an Oledb connection to read data from the excel into a DataGridView.
cn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;" + "data source=" + skuPath + ";Extended Properties=""Excel 12.0;HDR=YES;""")
q1 = "select * from [" + year + "$B4:AM300]"
da = New System.Data.OleDb.OleDbDataAdapter(q1, cn)
Try
cn.Open()
da.Fill(ds, "Table1")
Catch e As OleDb.OleDbException
Dim errorMsg As String
Dim i As Integer
errorMsg = ""
For i = 0 To e.Errors.Count - 1
errorMsg += "Index #" & i.ToString() & ControlChars.Cr _
& "Message: " & e.Errors(i).Message & ControlChars.Cr _
& "NativeError: " & e.Errors(i).NativeError & ControlChars.Cr _
& "Source: " & e.Errors(i).Source & ControlChars.Cr _
& "SQLState: " & e.Errors(i).SQLState & ControlChars.Cr
Next i
End Try
cn.Close()
dt = ds.Tables(0)
When the excel file is already open by another user you get this notification in excel:
And in those situations my code returns this error on the last line:
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll
Additional information: Cannot find table 0.
So i understand is that because the file is in use then the entire connection returns nothing and data table is therefore empty.
I found a few way of determining if a file is in use or not but nothing regarding how to read from a file in use.
Is it possible? and if so how?
Please remember i only need to read the file and if its possible to always open it as a readonly that would awesome!
You can't. You have to close the open file before read it even if you use the ODBC(read only).
Ref: http://forums.asp.net/t/1083489.aspx?open+a+Microsoft+Jet+OLEDB+4+0+connection+to+excel+file+read+only

Why this error .. command text was not set to command object

conn.Open()
Try
Dim update As New OleDbCommand
update.Connection = conn
update.CommandText = " UPDATE O_name SET fname= '" & Name1.Text & "' WHERE ID = '" & ID.Text & "'"
update.ExecuteNonQuery()
MsgBox("done")
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
conn.Close()
there is always Error
" Command Text was not set to command object "
what's the reason
please don't talk about parametrized query cause i'm asking about this specifically
A quick google for the error message has a link to this page as the first search result, where someone writes:
The problem was EvaluateAsExpression was not set to true..its working now..thanks again for the help :)
What kept you from using Google and finding it as quicky as I did?

Exception from HRESULT: 0x800A5077 when excute crystal report

i get error 0x800A5077, i try import CrystalActiveXReportViewerLib10 and CrystalReportsCommonObjectModelLib, but it still no work.
Call ReportConnection(CInspAuditList, "Pab_Prod")
CInspAuditList.ReportFileName = My.Application.Info.DirectoryPath & "\MAuditList.rpt"
Call SubReportConnection(CInspAuditList, "Pab_Prod")
CInspAuditList.set_ParameterFields(0, "mchno; " & frmMachine.machine & " ;true")
CInspAuditList.set_ParameterFields(1, "batch; " & CDbl(frmMachine.batch) - 1 & " ;true")
CInspAuditList.set_ParameterFields(2, "Points; " & InpStdPt & " ;true")
CInspAuditList.set_ParameterFields(3, "ovrpt; " & OvrPoints & " ;true")
CInspAuditList.Action = 1
the error occur when CInspAuditList.Action = 1
vb.net help me declare CInspAuditList as AxCrystal.AxCrystalReport
This is my function for connection:
Public Function ReportConnection(ByRef CrystalReport1 As AxCrystal.AxCrystalReport, ByRef dsnname As String) As Boolean
CrystalReport1.Connect = "dsn=" & dsnname & ";UID=" & gstrID & ";PWD=" & gstrPassword & ";DSQ="
End Function
I want to know the reason cause the error happen & my connection correct or not
That happened to me and that is because the report file (.rpt) contains a connection to a database that doesn't exists or cannot be located by the computer where you are running the program solution: open the report file (.rpt), menu database, verify database, checkout the parameters of the connection(mine is sql connection), ok, and you can see a msg that say the database is up to date, ok, save changes in report
If you ara using system dsn, crystal report needs admin rights for connect.
In the registry ODBC key is Local Machine and only grant Full Control to System and Administrators.

msaccess.exe opens while trying to release the object

I am opening a MS Access DB which is Password protected in vb.net using the folloing code:
Try
oDB = oDBEngine.OpenDatabase(Name:=strFullFileName, Options:=False, _
ReadOnly:=False, Connect:="")
Catch ex As Exception
strError = "File is password protected."
Exit Function
End Try
But while releasing the object the msaccess.exe opens up automatically.
**System.Runtime.InteropServices.Marshal.ReleaseComObject(object)**
Could anyone help me, how to resolve the issue....
Rather than using OpenDatabase to get the error, how about a connection string?
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFile & ";" & _
"Persist Security Info=False"
This will also give an error if a password is not supplied.