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.
Related
First time questioner, be gentle
I'm trying to connect to a Teradata database using ODBC. When the code was originally written it worked. We have since upgraded the ODBC drivers for Teradata.
I tried connecting using VBA (Excel) as we still have some old code lying around
VBA code (simplified)
private FConnection as New ADODB.Connection
sub DBConnect(DSNName as string, UserName as string, Password as string)
Set FConnection = New ADODB.Connection
FConnection.Open DSNName, UserName, Password
This works with no issues. It also works if I use
FConnection.Open "DSN=" & DSNName & ";UID=" & UserName & ";PWD=" & Password & ";"
So I know the ODBC connection is not an issue.
Trying the same with VB.NET
Dim FConnection As Odbc.OdbcConnection
try
FConnection = New Odbc.OdbcConnection()
FConnection.ConnectionString = "DSN=" & DSNName & ";UID=" & UserName & ";PWD=" & Password & ";"
FConnection.Open()
Catch ex As Odbc.OdbcException
MessageBox.Show(ex.Message)
End Try
This results in
ERROR [08001] [Teradata][socket error] (439) WSA E HostUnreach: The Teradata server can't currently be reached over this network
I've tried a number of variations on the Connection string but nothing.
EDIT: I tried using Teradata.net instead of ODBC, but all variations of that end up with a Socket Exception in System.Net.Dns.GetAddrInfo
Pinging the server name works without issue
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!
I have done developing and tried debugger and the code run fine in my laptop, but when Publishing or even using Release mode and than using it in other computers it show null exception
in this part of code
For Each r As DataRow In Access.dbDataTable.Rows
Check = r("EmployeeType")
Next
this one used in login Form and yes I forget to mention I use Access DB
I am really confused it's work fine than why it show exception
by the way my connection string
Dim mypath = Application.StartupPath & "\test.accdb"
Dim mypassword = "test"
Private dbConnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & mypath & ";Jet OLEDB:Database Password=" & mypassword)
exception shown is NullRefrenceException
I have solved the problem if anyone got same problem
try to check the version of ms access it should have same version
also check connection string
Private dbConnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & mypath & ";Jet OLEDB:Database Password=" & mypassword)
Microsoft.ACE.OLEDB.12.0 Need to be changed to same version of ms access targeted PC
The following code works perfectly fine on my computer. I cannot understand why it's not working on another persons computer. Can someone lead me towards ideas that may help trouble shoot this?
The error (with on error commented out) is that the array isn't being loaded with data. Get an error like "either bof or eof is true for the current record"
Also I can tell you if the on error GoTo NEXTT is left on.. it goes there and tries to erase the array and returns a wrong data type error. Makes me think the array is empty.
I checked Conn.State and I can confirm that the connection is open.
Function sbADO(ban_id, upc_id, div_id)
'Must add Activex data objects libaray 2.8
Dim sSQLSting As String
On Error GoTo nextt
Dim Conn As New ADODB.Connection
Dim mrs As New ADODB.Recordset
Dim DBPath As String, sconnect As String
DBPath = ThisWorkbook.FullName
'You can provide the full path of your external file as shown below
sconnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath _
& ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";"
Conn.Open sconnect
sSQLSting = "SELECT * From [data$] where BANNER_ID IN (" & ban_id & ") AND UPC_ID IN (" & upc_id & ") AND DIVISION_ID IN (" & div_id & ") " 'Your SQL Statemnt (Table Name= Sheet Name=[DataSheet$])
mrs.Open sSQLSting, Conn
'=>Load the Data into an array
ReturnArray = mrs.GetRows
''OR''
'=>Paste the data into a sheet
'Sheets("Sheet1").Range("A2").CopyFromRecordset mrs
'Close Recordset
mrs.Close
'Close Connection
Conn.Close
'
Exit Function
nextt:
Erase ReturnArray
'mrs.Close
Conn.Close
'MsgBox (ReturnArray(6, 2)) '(feild, row)
End Function
The problem is because
DBPath = ThisWorkbook.FullName <-- the workbook is set to read only.
Removing read only status fixes the issue.
It seems like you're using ADO to query data in the same workbook? That might be for the purposes of simplifying this problem for SO, but it would be easier and faster to get the array you need by referring to the range directly. But in this answer, I'll assume that you really do want to use ADO.
You're trying to use ADO to open the workbook, but you're not specifying the ConnectionString or Open methods with any read-only arguments. Try making these adjustments:
'Add Mode=Read
sconnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & _
";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";Mode=Read;"
'Add adLockReadOnly
mrs.Open sSQLSting, Conn, , adLockReadOnly
Dim con As New OleDb.OleDbConnection
Sub connecttodatabase(ByVal fileselected As String)
Dim databasepassword
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = " & fileselected
Try
con.Open()
Catch e As OleDb.OleDbException
If e.Message = "Not a valid password." Then
Console.WriteLine("Database has a password. Please enter password to continue.")
databasepassword = Console.ReadLine()
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = " & fileselected & ";JetOLEDB:Database Password=" & databasepassword & ";"
con.Open()
End If
errorid = 1
Finally
End Try
End Sub
The error I am encountering occurs at the second con.Open() when I try to connect to a .mdb database file which I created in access, the function correctly tells me I have a password, but then once I enter my password I get the error defined in the title, and I have no idea why. Any help would be greatly appreciated.
Try this instead:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=YOURPASS;
Also, what exception are you getting from the first call to open the db? Maybe it's same problem: the ISAM isn't present. Try reinstalling MDAC:
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=78cac895-efc2-4f8e-a9e0-3a1afbd5922e