Re: Newbie with Database Connection Problem by W
W
Tue Oct 25 14:54:58 CDT 2005
So it fails when you try to open the connection? The first thing to do then
is Try/catch the open statement and see what the Exception tells you if
anything. Verify the connection string, the values of the paramaters etc
and just try to pick off the low hanging fruit . If it's 0 or 1, then
you're going to connect to different databases. so check the Connection
String property ( you acn use a File.Exists as well for the path /file of
the *mdb file to make sure it exists). Make sure the file does exist and
that you have permission to acccess it. Also, just to help narrow thigns
down, use a For loop to access each fo the values in the command's
parameters collection, make sure the values are what you expect them to be,
it
For the file exists stuff, use this:
' At the beginning of your code file, use Imports System.Diagnostics
Imports System.IO 'If they aren't already there
Debug.Assert (File.Exists("J:\Database\MasterDB.mdb"),
"J:\Database\MasterDB.mdb "& " does not appear to exist")
Debug.Assert (File.Exists("J:\Database\TestDB.mdb"), "J:\Database\TestDB.mdb
"& " does not appear to exist")
For i as Int32 = 0 to UP.Parameters.Count -1
Debug.WriteLine(UP.Parameters(i).ToString())
Next i
Also, can you isolate what is causing the value of ind to change?
"No_So_Clever" <NOSPAM@NOSPAM.net> wrote in message
news:xvWdnaJ5yeR8e8DeSa8jmw@karoo.co.uk...
> Hi there,
> I`ve added the line in and depending on what I select in my Combo Box
> (Database 1 or Database 2) it gives me a 0 or a 1. Now tho my App Fails on
>
> Con.Open
>
> with the following Error:
>
> Additional information: No error information available:
> DB_SEC_E_AUTH_FAILED(0x80040E4D).
>
> My Code is:
>
> Dim UP As New OleDb.OleDbCommand
> Dim Con As New OleDb.OleDbConnection
> Dim Read As OleDb.OleDbDataReader
> Dim Plus As Integer
> Public CurrentForm As System.Windows.Forms.Form
> Private Sub Login_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Connection string
> Con.ConnectionString = Connection.String
> 'Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=J:\Database\MasterDB.mdb"
> UP.Connection = Con
> UP.CommandType = CommandType.Text
> UP.CommandText = "Select * From Passwords Where Users_Name=? and
> Users_Password=?"
> End Sub
> Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnLogin.Click
> Connection.setString(Me.cboSelectDB.SelectedIndex)
> If txtUserName.Text.Trim = "" Then
> MessageBox.Show("Please fill your User Name !", "Password",
> MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
> txtUserName.Focus()
> Exit Sub
> End If
> If txtPassword.Text.Trim = "" Then
> MessageBox.Show("Please fill your Password !", "Password",
> MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
> txtPassword.Focus()
> Exit Sub
> End If
> 'Admin
> UP.Parameters.Add("user", Data.OleDb.OleDbType.Variant)
> UP.Parameters.Add("password", Data.OleDb.OleDbType.Variant)
> UP.Parameters("user").Value = txtUserName.Text
> UP.Parameters("password").Value = txtPassword.Text
> 'Open database connection
> Con.Open()
> ' Read information from database
> Read = UP.ExecuteReader
> ar()
> ' Close database connection
> Con.Close()
> End Sub
> Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnCancel.Click
> Me.Close()
> End Sub
>
> Many Thanks
> Si
>
>
> "W.G. Ryan - MVP" <WilliamRyan@nospam.gmail.com> wrote in message
> news:OI8R8uM2FHA.3332@TK2MSFTNGP15.phx.gbl...
>> Ok, but what value does ind have in this line?
>> mLocation = connArray(ind).ToString
>> if this is a winforms application, stick this in the line before it:
>>
>> MessageBox.Show(ind.ToString())
>>
>> "No_So_Clever" <NOSPAM@NOSPAM.net> wrote in message
>> news:3rGcnR2uQ9ojj8DeSa8jmw@karoo.co.uk...
>>> Hi there Thanks again for your help but ....Sorry I don`t understand
>>> what you mean:(
>>>
>>> Like I said im a newbie - would I put:
>>>
>>> Dim connArray As New ArrayList
>>> connArray.Add("J:\Database\MasterDB.mdb")
>>> connArray.Add("J:\Database\TestDB.mdb")
>>> Try
>>> mLocation = connArray(ind).ToString
>>> Catch indException As System.Exception
>>> Throw indException
>>> End Try
>>>
>>> Cheers
>>> NSC
>>>
>>> "W.G. Ryan - MVP" <WilliamRyan@nospam.gmail.com> wrote in message
>>> news:OLTn7rL2FHA.3864@TK2MSFTNGP12.phx.gbl...
>>>> Put a breakpoint right before the line that references ind and see what
>>>> the value is. Or use Debug.WriteLine(ind.ToString()); and see what
>>>> that tells you. Based on teh exception I think that may be the
>>>> problem.
>>>> "No_So_Clever" <NOSPAM@NOSPAM.net> wrote in message
>>>> news:G4ecnf95E4HFksDeSa8jmw@karoo.co.uk...
>>>>> Hi
>>>>>
>>>>> ind is the location of my Database.i think,
>>>>>
>>>>> To be honest im a newbie and i took th code from another prog, to try
>>>>> nd use in my app. So im a little unaware and now vey confused.
>>>>>
>>>>> Many Thanks
>>>>> NSC
>>>>>
>>>>> "W.G. Ryan - MVP" <WilliamRyan@nospam.gmail.com> wrote in message
>>>>> news:e6AScXL2FHA.916@TK2MSFTNGP10.phx.gbl...
>>>>>> What is the value of Ind?
>>>>>> "No_So_Clever" <NOSPAM@NOSPAM.net> wrote in message
>>>>>> news:UXydnSEwI9YXmMDeSa8jmw@karoo.co.uk...
>>>>>>> Hi,
>>>>>>>
>>>>>>> Wonder if Somebody could help me? I`ve been searching all over for a
>>>>>>> solution but am totally lost.
>>>>>>>
>>>>>>> I have a Class called Connection as below:
>>>>>>>
>>>>>>> Public Class Connection
>>>>>>> Private Shared mConnectionsstring As String =
>>>>>>> "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
>>>>>>> Private Shared mLocation As String
>>>>>>> Private Shared connArray As ArrayList
>>>>>>> Public Shared Sub setString(ByVal ind As Integer)
>>>>>>> Dim connArray As New ArrayList
>>>>>>> connArray.Add("J:\Database\MasterDB.mdb")
>>>>>>> connArray.Add("J:\Database\TestDB.mdb")
>>>>>>> mLocation = connArray(ind).ToString
>>>>>>> End Sub
>>>>>>> Public Shared ReadOnly Property [String]() As String
>>>>>>> Get
>>>>>>> Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mLocation &
>>>>>>> ";"
>>>>>>> End Get
>>>>>>> End Property
>>>>>>> End Class
>>>>>>>
>>>>>>> On my Main Form I have my Database Connection Setup as:
>>>>>>>
>>>>>>> Dim UP As New OleDb.OleDbCommand()
>>>>>>> Dim