I am trying to open a locally saved file (SQLite) to pull some rows from specific tables. The problem I encountered is that I keep getting errors that cannot be connected to the connection (provider: SQL network interfaces, error: 26 - server / instance location error), which makes sense, because it not SQL Server; this is only information stored in the local database file. So am I going about it wrong or is this the only method for processing a .db or similar file, and am I missing something?
Dim connection As String = "Data Source=" & Form1.connstring & "; Integrated Security=true"
Dim SQLConn As New SqlConnection
Dim SQLcmd As New SqlCommand
Dim SQLdr As SqlDataReader
SQLConn.ConnectionString = connection
SQLConn.Open()
SQLcmd.Connection = SQLConn
SQLcmd.CommandText = SQLstr
SQLdr = SQLcmd.ExecuteReader()
While SQLdr.Read()
MessageBox.Show(SQLdr.ToString)
Form1.ListBox1.Text = SQLdr.ToString
End While
SQLdr.Close()
SQLConn.Close()
Form1.connstring - .
" =", , .
, - -
:
Imports System.Data.SQLite 'Interop available on NuGet
Public Class _SQLite
Public Shared Sub SQLInq()
'Value to search as SQL Query - return first match
Dim SQLstr As String = "Select * FROM FsFileVersion WHERE FileDescription_LTH = 'Entry' LIMIT 1;"
'Define file to open - .path passed from parent form
Dim connection As String = "Data Source=" & _Compression.path
Dim SQLConn As New SQLiteConnection(connection)
Dim SQLcmd As New SQLiteCommand(SQLConn)
Dim SQLdr As SQLiteDataReader
SQLConn.Open()
SQLcmd.Connection = SQLConn
SQLcmd.CommandText = SQLstr
SQLdr = SQLcmd.ExecuteReader()
'For each query returned
While SQLdr.Read()
'Insert into textbox
Form1.Textbox1.Text = (SQLdr.GetString(SQLdr.GetOrdinal("FileVersion_LTH")))
End While
'End the connection
SQLdr.Close()
SQLConn.Close()
End Sub