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
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 connecting an access database to a datagrid view on vb and I am encountering an error
"Additional information: The 'Microsoft.ACE.OLEDB.12.0Data Source =
CUBSDatabase.accdb' provider is not registered on the local machine."
I am using visual studio version 2015, language visual basic.
My access database is saved in the bin in the debug folder
This is my code so far;
Any idea how to get rid of the error?
The error renders on the line // adt.Fill(datatable)
Imports System.Data.OleDb
Public Class Form1
Dim dbconn As New OleDbConnection
Dim adt As New OleDbDataAdapter
Dim ds As New DataSet
Dim datatable As New DataTable
Dim cmd As New OleDbCommand
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dbconn.ConenctionString = ("Provider=Microsoft.ACE.OLEDB.12.0" &
"Data Source = CUBSDatabase.accdb")
showData()
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
adt = New OleDbDataAdapter("insert into Student (FName, SName, Attendance, CA1, CA2, FinalExam) values ( '" & txtFName.Text & "','" & txtSName.Text & "', '" & txtAttendance.Text & "', '" & txtCA1.Text & "', '" & txtCA2.Text & "', '" & txtFinalExam.Text & "', )", dbconn)
adt.Fill(ds)
ds = New DataSet
MsgBox("Saved")
End Sub
Private Sub showData()
Dim dbcommand As String
dbcommand = "SELECT * FROM Students"
adt = New OleDbDataAdapter(dbcommand, dbconn)
datatable = New DataTable
adt.Fill(datatable)
DataGridView1.DataSource = datatable
End Sub
End Class
Maybe you just forgot a semicolon in your code, after your provider name, since normally you should have something like
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=...
If that's not your case, as per this answer to a similar question, you need to install the provider on your machine; as a preliminary check, you can follow another answer to the same question and see wheter you already have the dll including your provider, i.e. ACEOLEDB.DLL, at one of these paths:
C:\Program Files\Common Files\Microsoft Shared\OFFICE14
C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14
Of course you can adapt those paths to the Office version you have on your machine, which are listed in this answer, e.g.
Office 2007 12
Office 2010 14
Office 2013 15
Office 2016 16
EDIT: the following won't apply because Jet won't handle accdb files.
Last but not least, if you don't feel like installing anything or you want to perform a quick check of your code functionality, you can rewrite your connection string to use an older (legacy, perhaps despised) provider, i.e. Jet, which is included in Windows:
dbconn.ConenctionString = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = CUBSDatabase.accdb")
Of course there's a difference in terms of efficiency between the two.
Use this format.
Dim cons As String = "provider= Microsoft.ACE.OLEDB.12.0; Data Source=D:\Users\rjimenez\Documents\QAdatabase.mdb"
but of you still got an error. Download
AccessDatabaseEngine
Hope it will works!
I just created a Windows forms application with SQL Server 2008. I created the Setup File and installed the application.
When I click on any forms from the menu it shows an error
a network related or instance specific error occurs.
And hence couldn't find the server and so.
I guess I have done something wrong in connection string
Here is my connection string
Dim constr As String = "Data Source= server=.\SQLEXPRESS;AttachDbFilename=" & Application.StartupPath & "\jshed.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
Can somebody help me?
remove the following from the connection string
server=
try this
Dim constr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & Application.StartupPath & "\jshed.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
After spending a few days researching and trying to figure this out solo, I could really use some help.
I'm trying to query the As400's database directly from .Net without the use of a As400 program file. I have very little support other than "go ahead and try" from the As400 administrators (I'm being told what I'm attempting hasn't been done here before).
I'd really like to use CWBX. The code below successfully connects, but I could really use a pointer in the right direction on how to build a query:
Dim As400 As New AS400System
Dim AsProgram As New cwbx.Program
Dim AsCommand As New cwbx.Command
Dim strQuery As String
As400.Define("AS400")
As400.UserID = ""
As400.Password = ""
As400.IPAddress = ""
As400.Connect(cwbcoServiceEnum.cwbcoServiceRemoteCmd)
If As400.IsConnected(cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 1 Then
MsgBox("Valid Connection")
Else
MsgBox("Invalid Connection")
Exit Sub
End If
'-----------------------------------------------------------------------------------------
'Trying to figure out first if this syntax is correct, and if so... where/how to call it??
'-----------------------------------------------------------------------------------------
strQuery = "SELECT * FROM Library.File WHERE FILEFIELD='Criteria'"
' ---
AsProgram.LibraryName = ""
AsProgram.ProgramName = "" '?
AsProgram.system = As400
'Assuming this will end up being a program call?
'AsProgram.Call()
As400.Disconnect(cwbcoServiceEnum.cwbcoServiceRemoteCmd)
I'm very open to any other methods/suggestions. I've looked for guides from IBM's site as well as MSDN and neither actually do direct querying without the use of an As400 program file. Is this even possible?
Here is a simple console app that will retrieve all the records from one table and display the row count.
Imports System.Data.OleDb
Module Module1
Sub Main()
Dim cmd As New OleDbCommand
Dim table As String = "YOUR TABLE"
cmd.CommandText = "SELECT * FROM " & table
Dim ip As String = "YOUR AS/400 IP GOES HERE"
Dim user As String = "YOUR USER ID"
Dim pass As String = "YOUR PASSWORD"
Dim defaultLib As String = "YOUR LIBRARY"
Dim connstring As String = "Provider=IBMDA400;" & _
"Data Source=" & ip & ";" & _
"Force Translate=0;" & _
"Default Collection=" & defaultLib & ";" & _
"User ID=" & user & ";" & _
"Password=" & pass
cmd.Connection = New OleDbConnection(connstring)
cmd.Connection.Open()
Dim dr As OleDbDataReader = cmd.ExecuteReader
Dim dt As New DataTable
dt.Load(dr)
Console.WriteLine(dt.Rows.Count)
Console.WriteLine("Press ENTER to close...")
Console.ReadLine()
End Sub
End Module
The remotecmd service is basically a Rexcd daemon. Not sure why you're messing with that when you want to simple query a DB table. The integrated DB in IBM i is accessible via ODBC, OLEDB, JBDC and most importantly for you a ADO.NET provider.
http://www-03.ibm.com/systems/power/software/i/access/windows/dotnet.html
All of the above mentioned drivers are available in the IBM i Access software. Note that while some of the IBM i Access features are chargeable, ex 5250 emulation, and you must have bought a license; the data access providers are not.
Included in the IBM i Access package is a collection of documentation known as the "Programmers Toolkit"
An example using the .NET data provider from that toolkit:
Public Sub Example()
Dim cn As iDB2Connection = New iDB2Connection("DataSource=mySystemi;")
Dim da As New iDB2DataAdapter("select * from mylib.mytable", cn)
End Sub
Lastly note that the (free) .NET provider doesn't support Microsoft's Entity Framework (EF). If you need EF support, you'll have to pay for DB2 Connect
http://www-03.ibm.com/software/products/en/db2-connect-family
I am trying to connect Visual Basic to MS Access using ADODB. But as I execute my code, it prompts: "Provider cannot be found.It may not be installed properly." But when I check on my directory I've got my "msjetoledb40.dll" installed.
Here is my code:
Dim conn As ADODB.Connection, rec As ADODB.Recordset
Sub sample()
Set conn = New ADODB.Connection
conn.Open ("Provider=Microsoft.Jet.OLEDB 4.0;Data Source=C:\sample.mdb;Persist Security Info=false;")
End Sub
This would be better:
Sub sample()
Dim conn As ADODB.Connection, rec As ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\sample.mdb;"
conn.Open
End Sub
You missed a point.
Microsoft.Jet.OLEDB 4.0 => Microsoft.Jet.OLEDB.4.0
Ref: http://www.connectionstrings.com/.
Confirming the version of your MS Office on which the script is running. If you have installed MS Office 2013 or later, you should revise the connection string from:
Provider=Microsoft.Jet.OLEDB 4.0;Data Source=C:\sample.mdb;Persist Security Info=false;
to:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\sample.mdb;Persist Security Info=false;
At least, this sovled my problem.
My solution:
Error 3706
cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sPath & ";Persist Security Info=False;"
Just Change 12.0 for 15.0
cs = "Provider=Microsoft.ACE.OLEDB.15.0;Data Source=" & sPath & ";Persist Security Info=False;"
and works, always you must to try change the version of the controller!.