Results 1 to 5 of 5

Thread: [RESOLVED] [2008] can someone help me with this???

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2002
    Location
    Florida
    Posts
    56

    Resolved [RESOLVED] [2008] can someone help me with this???

    Im working on another db class and i cant get it to work
    Im trying to connect to an access 2000 database and all i get are exeption errors. Can someone help???

    here is my code
    Code:
    Imports System.Data.SqlClient
    
    
    Public Class clsDB
        Private database_ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\bin\Debug\data\mydb.mdb;"
    
        Private database_Connection As New SqlConnection()
        Private database_Sql_Statement As String = ""
        Public Reader As SqlDataReader
    
        Public Sub OpenDatabaseConnection()
            Try
                database_Connection.ConnectionString = database_ConnectionString
                database_Connection.Open()
            Catch ex As Exception
                Addlvitems("DataBase Connection Error: " + ex.Message.ToString(), "System")
            End Try
        End Sub
        Public Sub CloseDatabaseConnection()
            Try
                Reader.Close()
                If database_Connection.State <> Data.ConnectionState.Closed Then
                    Reader.Close()
                    database_Connection.Close()
                End If
            Catch ex As Exception
                Addlvitems("DataBase Close Error: " + ex.Message.ToString(), "System")
            End Try
        End Sub
    
        Public Function RunSqlStatement(ByVal SQL_Statement As String, ByVal where As String) As String
            RunSqlStatement = ""
            Try
                Dim cmd As New System.Data.SqlClient.SqlCommand(SQL_Statement, database_Connection)
                Reader = cmd.ExecuteReader
                If Reader.HasRows Then
                    Do While Reader.Read()
                        RunSqlStatement = Reader.Item(where)
                    Loop
                Else
                    RunSqlStatement = " "
                End If
    
                Return RunSqlStatement
            Catch ex As Exception
                Addlvitems("Sql Error: " + ex.Message.ToString(), "System")
            End Try
        End Function
    
    End Class
    Were there is code there is a way...

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] can someone help me with this???

    Let's address some housekeeping issues first. For a start, please provide descriptive titles for your threads. Think about it. What use would thread titles be if everyone just asked for help? We know you want help. You wouldn't be posting otherwise. The thread title is to give us a general idea of what you want help with.

    Second, don't tell us that you get exceptions without telling us what the error messages are. They're provided to you for a reason: to help you diagnose the issue. If you want us to diagnose the issue then common sense dictates that you provide them to us. In this case I can see the issue straight off but you wouldn't have known that and it will certainly not always be the case.

    As for the issue, your connection string is wrong. Application.StartupPath is the path to the folder that the application started from. If you're running in the debugger then that is the bin\Degug folder. If you actually looked to see what database_ConnectionString contained you'd have seen that the path was wrong. The error message would presumably have told you that the connection failed, so the connection string should have been the first place you looked.

    Besides that, you shouldn't be using Application.StartupPath anyway. This is all you need:
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\data\mydb.mdb;"
    That will resolve to the right path at run time.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2002
    Location
    Florida
    Posts
    56

    Re: [2008] can someone help me with this???

    ok the error im getting is "Keyword not Supported: 'Provideder'"
    Were there is code there is a way...

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2002
    Location
    Florida
    Posts
    56

    Re: [2008] can someone help me with this???

    ok i tried what you said and it says the same error
    Were there is code there is a way...

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] can someone help me with this???

    Well there you go. Now that I have the error message I can see what the issue is that I missed before. You're using an SqlConnection, which is for SQL Server ONLY. To connect to Access you need to use an OleDbConnection. Now do you see why you need to provide error messages?

    What I said before still applies though. Your connection string is still wrong as it was.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width