OleDbConnection problem (VB.NET)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SyGC
    New Member
    • Feb 2008
    • 17

    OleDbConnection problem (VB.NET)

    Hello,

    Im trying to connect to a MySQL DB on my home network (testing purposes) using the following VB.NET code;
    Code:
    Imports System.Data.OleDb
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    
            Dim SQLConnection As OleDbConnection
            Dim SQLInsertCMD As OleDbCommand
            Dim sConnString As String = _
                "Provider=OleMySql.MySqlSource.1;" & _
                "Data Source=192.168.1.121, 3306;" & _
                "Initial Catalog=airproductsipdb;" & _
                "User Id=[B]USERNAME[/B];" & _
                "Password=[B]PASSWORD[/B]"
    
            SQLConnection = New OleDb.OleDbConnection(sConnString)
            SQLConnection.Open()
    
            SQLInsertCMD = New OleDb.OleDbCommand("DROP TABLE table ;")
    
        End Sub
    When i execute the code i dont get any error messages from VS such as
    [2003]: Can't connect to MySQL server on '192.168.1.122 3306' (10060)
    Say if the IP address is different (.122 instead of .121)

    I have set up MySQL to allow Remote connections on port 3306 for the username and password (above).

    I have installed MySQL P which actually does allow me to to get a connection to the DB as it brings back the tables in the DB.

    see attached image

    However through VS i am unable to display the table data. i get the following error message...
    Code:
    SQL Execution Error
    Executed SQl statement: SELECT site_id, Gateway_IP, Sitename, SubentAddress, SubnetMask, BroadcastAddress FROM sitename
    Error Source: System.Data
    Error Message: MySQL OLE DB Provider has not been activated
    Im confused as to whether i have a working connection or not. So ive included a DROP TABLE command to parse to the DB. However the table in question doesnt get dropped. Ive also tried INSERT statements etc but none of which have worked.

    So i am unsure whether it is the Connection or SQL Command code that is wrong.

    I am using WAMP Server 2.0 with Apache 1.3.39 and MySQL 5.0.45.

    If any one has some ideas please help!!!

    Thanks in advance

    Sy
    Attached Files
    Last edited by SyGC; Mar 15 '08, 01:45 PM. Reason: Adding additional information
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    Try the connectionstrin g below instead of the one you have...I'm really not sure you've got the format right...

    Driver={MySQL ODBC 3.51 Driver};Server=[SERVER ADDRESS];Port=[PORT NUMBER];Database=[DATABASE NAME];User=[USERNAME]; Password=[PASSWORD];Option=3;

    Put a breakpoint right on the connect call, then when your application breaks out use F8 to step line by line. When you've stepped past the connect call hold your mouse over the connection object and you should see your connectionstrin g if it connected. If it didn't connect, you'll see it says "Nothing".

    Comment

    • SyGC
      New Member
      • Feb 2008
      • 17

      #3
      Originally posted by balabaster
      Try the connectionstrin g below instead of the one you have...I'm really not sure you've got the format right...

      Driver={MySQL ODBC 3.51 Driver};Server=[SERVER ADDRESS];Port=[PORT NUMBER];Database=[DATABASE NAME];User=[USERNAME]; Password=[PASSWORD];Option=3;

      Put a breakpoint right on the connect call, then when your application breaks out use F8 to step line by line. When you've stepped past the connect call hold your mouse over the connection object and you should see your connectionstrin g if it connected. If it didn't connect, you'll see it says "Nothing".
      Hi balabaster,

      thanks for getting back to me.

      Ive tried your Connection string replacing mine. I inserted the breakpoint as you said and unfortunatley i get the "nothing"respon se when holding my mouse over the connection object....

      Code:
      ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=192.168.1.121;Port=3306;Database=airproductsipdb;User=[B]USERNAME[/B];Password=[B]PASSWORD[/B];Option=3;"
      
      ConnectionTimeout = 15
      Container =  Nothing
      DataSource = ""
      Driver = ""
      ServerVersion = {"Invalid operation. The connection is closed."}
      Site = Nothing
      State = Closed{0}
      So i checked and notcied i didnt have the ODBC driver installed. I have downloaded and installed Driver 3.51.23 also setting it up in Data Sources ODBC. Now i get the following......

      Code:
      ConnectionString = "Driver={MySQL ODBC 3.51 Driver};[U]Datasource=wampmysqld;[/U]Server=192.168.1.121;Port=3306;Database=airproductsipdb;User=[B]USERNAME[/B];Password=[B]PASSWORD[/B];Option=3;"
      
      ConnectionTimeout = 15
      Container =  Nothing
      Database = "airproductsipdb"
      DataSource = "192.168.1.121 via TCP/IP"
      Driver = "myodbc3.dll"
      ServerVersion = "5.0.45-community-nt"
      Site = Nothing
      State = Open{1}
      Now from what you've said, does this show i have an established connection? Sorry im rather new to VB.NET , maybe getting ahead of myself.
      Also if i do does that mean my ODBC Command syntax of DROP TABLE table is incorrect?

      Code:
      Dim SQLInsertCMD As Odbc.OdbcCommand
      SQLInsertCMD = New Odbc.OdbcCommand("DROP TABLE table ;")

      Thanks

      Sy
      Last edited by Plater; Mar 19 '08, 08:59 PM. Reason: removing username/password

      Comment

      • balabaster
        Recognized Expert Contributor
        • Mar 2007
        • 798

        #4
        Originally posted by SyGC
        Hi balabaster,

        thanks for getting back to me.

        Ive tried your Connection string replacing mine. I inserted the breakpoint as you said and unfortunatley i get the "nothing"respon se when holding my mouse over the connection object....

        Code:
        ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=192.168.1.121;Port=3306;Database=airproductsipdb;User=[B]USERNAME[/B];Password=[B]PASSWORD[/B];Option=3;"
         
        ConnectionTimeout = 15
        Container = Nothing
        DataSource = ""
        Driver = ""
        ServerVersion = {"Invalid operation. The connection is closed."}
        Site = Nothing
        State = Closed{0}
        So i checked and notcied i didnt have the ODBC driver installed. I have downloaded and installed Driver 3.51.23 also setting it up in Data Sources ODBC. Now i get the following......

        Code:
         
        ConnectionString = "Driver={MySQL ODBC 3.51 Driver};[u]Datasource=wampmysqld;[/u]Server=192.168.1.121;Port=3306;Database=airproductsipdb;User=[B]USERNAME[/B];Password=[B]PASSWORD[/B];Option=3;"
         
        ConnectionTimeout = 15
        Container = Nothing
        Database = "airproductsipdb"
        DataSource = "192.168.1.121 via TCP/IP"
        Driver = "myodbc3.dll"
        ServerVersion = "5.0.45-community-nt"
        Site = Nothing
        State = Open{1}
        Now from what you've said, does this show i have an established connection? Sorry im rather new to VB.NET , maybe getting ahead of myself.
        Also if i do does that mean my ODBC Command syntax of DROP TABLE table is incorrect?

        Code:
         
        Dim SQLInsertCMD As Odbc.OdbcCommand
        SQLInsertCMD = New Odbc.OdbcCommand("DROP TABLE table ;")

        Thanks

        Sy
        The fact that the State property is now set to open is promising... can you provide the line of code where you instantiate the connection object?

        If you are connecting using the OleDbConnection object, then the reason your drop command isn't working is because you're using the OdbcCommand where you should be using the OledbCommand (in the Oledb namespace)

        Comment

        • SyGC
          New Member
          • Feb 2008
          • 17

          #5
          Originally posted by balabaster
          The fact that the State property is now set to open is promising... can you provide the line of code where you instantiate the connection object?

          If you are connecting using the OleDbConnection object, then the reason your drop command isn't working is because you're using the OdbcCommand where you should be using the OledbCommand (in the Oledb namespace)

          Hey,

          Ok ive changed the odbc command to OleDB Command. I dont totally understand what you mean by the line of code for 'instantiating' the connection object (:$)...sorry..( ill get 'Newb' tattooed across my forehead!) The code below is all ive been working with ...

          Code:
              Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
          
                  Dim SQLConnection As Odbc.OdbcConnection
          
                  Dim SQLInsertCMD As OleDb.OleDbCommand
          
                  Dim sConnString As String = _
                  "Driver={MySQL ODBC 3.51 Driver};" & _
                  "Datasource=wampmysqld;" & _
                  "Server=192.168.1.121;" & _
                  "Port=3306;" & _
                  "Database=airproductsipdb;" & _
                  "User=[B]USERNAME[/B];" & _
                  "Password=[B]PASSWORD[/B];" & _
                  "Option=3;"
          
                  SQLConnection = New Odbc.OdbcConnection(sConnString)
                  SQLConnection.Open()
          
                  SQLInsertCMD = New OleDb.OleDbCommand("DROP TABLE table ;")
              End Sub
          Ive attached some screen shots also of the MySQL Connector ODBC configuration. ...if that helps.


          Sy
          Attached Files

          Comment

          • balabaster
            Recognized Expert Contributor
            • Mar 2007
            • 798

            #6
            Originally posted by SyGC
            Hey,

            Ok ive changed the odbc command to OleDB Command. I dont totally understand what you mean by the line of code for 'instantiating' the connection object (:$)...sorry..( ill get 'Newb' tattooed across my forehead!) The code below is all ive been working with ...

            Code:
             
            Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
             
            Dim SQLConnection As Odbc.OdbcConnection
             
            Dim SQLInsertCMD As OleDb.OleDbCommand
             
            Dim sConnString As String = _
            "Driver={MySQL ODBC 3.51 Driver};" & _
            "Datasource=wampmysqld;" & _
            "Server=192.168.1.121;" & _
            "Port=3306;" & _
            "Database=airproductsipdb;" & _
            "User=[B]USERNAME[/B];" & _
            "Password=[B]PASSWORD[/B];" & _
            "Option=3;"
             
            SQLConnection = New Odbc.OdbcConnection(sConnString)
            SQLConnection.Open()
             
            SQLInsertCMD = New OleDb.OleDbCommand("DROP TABLE table ;")
            End Sub
            Ive attached some screen shots also of the MySQL Connector ODBC configuration. ...if that helps.


            Sy
            Okay, I'm understanding your code a little better now... the line of code
            Code:
            SQLConnection = New Odbc.OdbcConnection(sConnString)
            is where you're instantiating the connection - "instantiat e: create an instance of". I notice now that you're actually using the OdbcConnection object to connect, so you were actually right in using the OdbcCommand to execute the command. I personally prefer the Oledb namespace to the Odbc one - however, each has their advantages and disadvantages and really in many cases, it comes down to personal preference and/or availability of drivers. What is critical though is that whichever you use for your connection object, you must use the same type for your command object and consequently parameters etc.

            There is one issue with your code that will prevent your drop command running and that is that you're not actually executing it. I would probably use code similar to the following:

            Code:
            Dim sConString As String = _
            "Driver={MySQL ODBC 3.51 Driver};" & _
            "Datasource=wampmysqld;" & _
            "Server=192.168.1.121;" & _
            "Port=3306;" & _
            "Database=airproductsipdb;" & _
            "User=[B]USERNAME[/B];" & _
            "Password=[B]PASSWORD[/B];" & _
            "Option=3;"
             
            Dim oCon As Oledb.OleDbConnection = New Oledb.OledbConnection(sConnString)
            Try
              oCon.Open()
              Dim oCmd As Oledb.OledbCommand = New OleDb.OleDbCommand("DROP TABLE table;")
             
              'This is the crucial line that you're missing
              oCmd.ExecuteNonQuery() 'This will execute a query that doesn't require a response
              ''If you require a response then you would use the commented out code block below:
              'Dim oRdr As Oledb.OledbDataReader = oCmd.ExecuteReader()
              'If oRdr.HasRows Then
              ' While oRdr.Read
              ' Dim sOut As String = oRdr("Field1")
              '' etc...
              ' End While
              'End If
            Catch ex As Exception
              MsgBox ex.Message
            Finally
              oCmd.Dispose()
              oCon.Close()
              oCon.Dispose()
            End Try

            Comment

            • SyGC
              New Member
              • Feb 2008
              • 17

              #7
              Originally posted by balabaster
              Okay, I'm understanding your code a little better now... the line of code
              Code:
              SQLConnection = New Odbc.OdbcConnection(sConnString)
              is where you're instantiating the connection - "instantiat e: create an instance of". I notice now that you're actually using the OdbcConnection object to connect, so you were actually right in using the OdbcCommand to execute the command. I personally prefer the Oledb namespace to the Odbc one - however, each has their advantages and disadvantages and really in many cases, it comes down to personal preference and/or availability of drivers. What is critical though is that whichever you use for your connection object, you must use the same type for your command object and consequently parameters etc.

              There is one issue with your code that will prevent your drop command running and that is that you're not actually executing it. I would probably use code similar to the following:

              Code:
              Dim sConString As String = _
              "Driver={MySQL ODBC 3.51 Driver};" & _
              "Datasource=wampmysqld;" & _
              "Server=192.168.1.121;" & _
              "Port=3306;" & _
              "Database=airproductsipdb;" & _
              "User=[B]USERNAME[/B];" & _
              "Password=[B]PASSWORD[/B];" & _
              "Option=3;"
               
              Dim oCon As Oledb.OleDbConnection = New Oledb.OledbConnection(sConnString)
              Try
                oCon.Open()
                Dim oCmd As Oledb.OledbCommand = New OleDb.OleDbCommand("DROP TABLE table;")
               
                'This is the crucial line that you're missing
                oCmd.ExecuteNonQuery() 'This will execute a query that doesn't require a response
                ''If you require a response then you would use the commented out code block below:
                'Dim oRdr As Oledb.OledbDataReader = oCmd.ExecuteReader()
                'If oRdr.HasRows Then
                ' While oRdr.Read
                ' Dim sOut As String = oRdr("Field1")
                '' etc...
                ' End While
                'End If
              Catch ex As Exception
                MsgBox ex.Message
              Finally
                oCmd.Dispose()
                oCon.Close()
                oCon.Dispose()
              End Try

              Hey balabaster

              Thanks for you help today. Helpfull to have the commented sections, makes learning a lot easier. Since looking at your code a few developements. I see you've used the OleDB method so ive adapted my connection string work with this

              Code:
              Dim sConnString As String = _
                    [U][B]  "Provider=OleMySql.MySqlSource.1;"[/B][/U] & _
                      "Datasource=wampmysqld;" & _
                      "Server=192.168.1.121;" & _
                      "Port=3306;" & _
                      "Database=airproductsipdb;" & _
                      "User=[B]USERNAME[/B];" & _
                      "Password=[B]PASSWORD[/B];" & _
                      "Option=3;"

              When Running the codei get the following error...

              'DB Remote Connection to WAMP'
              "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done."

              this occurs with the following code..

              Code:
              Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
              
                      Dim SQLConnection As OleDb.OleDbConnection
              
                      'Dim SQLInsertCMD As OleDb.OleDbCommand
              
                      Dim sConnString As String = _
                      "Provider=OleMySql.MySqlSource.1;" & _
                      "Datasource=wampmysqld;" & _
                      "Server=192.168.1.121;" & _
                      "Port=3306;" & _
                      "Database=airproductsipdb;" & _
                      "User=[B]USERNAME[/B];" & _
                      "Password=[B]PASSWORD[/B];" & _
                      "Option=3;"
              
                      SQLConnection = New OleDb.OleDbConnection(sConnString)
              
                      Dim oCon As OleDb.OleDbConnection = New OleDb.OleDbConnection(sConnString)
                      Try
                          oCon.Open()
                          Dim oCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("DROP TABLE table;")
              
                          'This is the crucial line that you're missing
                          oCmd.ExecuteNonQuery() 'This will execute a query that doesn't require a response
                          ''If you require a response then you would use the commented out code block below:
                          'Dim oRdr As Oledb.OledbDataReader = oCmd.ExecuteReader()
                          'If oRdr.HasRows Then
                          ' While oRdr.Read
                          ' Dim sOut As String = oRdr("Field1")
                          '' etc...
                          ' End While
                          'End If
                      Catch ex As Exception
                          MsgBox(ex.Message)
                      Finally
                          'oCmd.Dispose()
                          oCon.Close()
                          oCon.Dispose()
                      End Try
                  End Sub

              So i also tried your code with the ODBC method code as follows...

              Code:
              Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
              
                      Dim SQLConnection As Odbc.OdbcConnection
              
                      'Dim SQLInsertCMD As OleDb.OleDbCommand
              
                      Dim sConnString As String = _
                      "Driver={MySQL ODBC 3.51 Driver};" & _
                      "Datasource=wampmysqld;" & _
                      "Server=192.168.1.121;" & _
                      "Port=3306;" & _
                      "Database=airproductsipdb;" & _
                      "User=[B]USERNAME[/B];" & _
                      "Password=[B]PASSWORD[/B];" & _
                      "Option=3;"
              
                      SQLConnection = New Odbc.OdbcConnection(sConnString)
              
                      Dim oCon As Odbc.OdbcConnection = New Odbc.OdbcConnection(sConnString)
                      Try
                          oCon.Open()
                          Dim oCmd As Odbc.OdbcCommand = New Odbc.OdbcCommand("DROP TABLE table;")
              
                          'This is the crucial line that you're missing
                          oCmd.ExecuteNonQuery() 'This will execute a query that doesn't require a response
                          ''If you require a response then you would use the commented out code block below:
                          'Dim oRdr As Oledb.OledbDataReader = oCmd.ExecuteReader()
                          'If oRdr.HasRows Then
                          ' While oRdr.Read
                          ' Dim sOut As String = oRdr("Field1")
                          '' etc...
                          ' End While
                          'End If
                      Catch ex As Exception
                          MsgBox(ex.Message)
                      Finally
                          'oCmd.Dispose()
                          oCon.Close()
                          oCon.Dispose()
                      End Try
                  End Sub
              Whilst running this i get the error message 'ExecuteNonQuer y: Connection property has not been initialized'

              Thanks again,


              Sy

              Comment

              • balabaster
                Recognized Expert Contributor
                • Mar 2007
                • 798

                #8
                After your oCon.Open() line, add the line MsgBox(oCon.Sta te.ToString) this should tell you if the connection to the database was actually opened successfully or not.
                Last edited by Plater; Mar 19 '08, 09:04 PM. Reason: removed quote so message shows up

                Comment

                • balabaster
                  Recognized Expert Contributor
                  • Mar 2007
                  • 798

                  #9
                  Add the line:
                  MsgBox(oCon.Sta te.ToString) after the line oCon.Open. This will tell you if the connection is actually opened successfully or not. I think it's likely to do with your connection to your MySQL Server, unfortunately, I'm not a MySQL expert so I may not be able to help much there I'm afraid.

                  Comment

                  • SyGC
                    New Member
                    • Feb 2008
                    • 17

                    #10
                    Originally posted by balabaster
                    Add the line:
                    MsgBox(oCon.Sta te.ToString) after the line oCon.Open. This will tell you if the connection is actually opened successfully or not. I think it's likely to do with your connection to your MySQL Server, unfortunately, I'm not a MySQL expert so I may not be able to help much there I'm afraid.

                    Hey balabaster,

                    Thanks for all your help so far....life saver!

                    I added the MsgBox, and i get an "Open" response then followed by the other catch exception message box stating....'Exe cuteNonQuery: Connection Property has not been initialised.'

                    Could it be an issue with the ODBC setup on my developement environment? The screen shots i attached on a previous post show what ive configured. Noticing that in odBC Data Source Administrator i have under 'User DSN' my server connection name 'wampmysqld' with the ODBC driver 3.51 AND the same has been configured in the 'System DSN'


                    Any more helpful thoughts oh wise balabaster?

                    Thanks

                    Sy

                    Comment

                    • balabaster
                      Recognized Expert Contributor
                      • Mar 2007
                      • 798

                      #11
                      Originally posted by SyGC
                      Hey balabaster,

                      Thanks for all your help so far....life saver!

                      I added the MsgBox, and i get an "Open" response then followed by the other catch exception message box stating....'Exe cuteNonQuery: Connection Property has not been initialised.'

                      Could it be an issue with the ODBC setup on my developement environment? The screen shots i attached on a previous post show what ive configured. Noticing that in odBC Data Source Administrator i have under 'User DSN' my server connection name 'wampmysqld' with the ODBC driver 3.51 AND the same has been configured in the 'System DSN'


                      Any more helpful thoughts oh wise balabaster?

                      Thanks

                      Sy
                      I notice that you've configured all the necessary options to render the DataSource=WAMP-whatever-it-was completely redundant.

                      Maybe try dropping that option from your connectionstrin g. The standard .NET connectionstrin g to access a MySql database (at least according the http://www.connectionstrings.com/) is the following:

                      "Driver={My SQL ODBC 3.51 Driver};Server= data.domain.com ;Port=3306;Data base=myDataBase ;User=myUsernam e; Password=myPass word;Option=3;"

                      Notice that no ODBC DSN name is provided in that string, yet (presumably) still works. Also, I'd verify that the name of the driver is correct "MySQL ODBC 3.51 Driver" - verify that in your ODBC manager, you may actually be using a different driver and consequently need to change this. The string you require is the same as the name of the driver you choose in the ODBC manager.

                      In my experience though, when you're using a DSN, you only need to specify something akin to:

                      "DataSource=MyD SN;User=MyUsern ame;Password=My Password;"

                      Any relevant DSN options for that driver where the defaults are required to be overridden would be appended to the end of that string with a semi-colon delimiter. If you specified all the required options when you configured the DSN, then your connectionstrin g could be as simple as:

                      "DataSource=MyD SN;"

                      Of course, think about security when you do things like this...obviousl y not having to specify a username and password when accessing a database is somewhat frivolous in most cases.

                      Comment

                      • SyGC
                        New Member
                        • Feb 2008
                        • 17

                        #12
                        Originally posted by balabaster
                        I notice that you've configured all the necessary options to render the DataSource=WAMP-whatever-it-was completely redundant.

                        Maybe try dropping that option from your connectionstrin g. The standard .NET connectionstrin g to access a MySql database (at least according the http://www.connectionstrings.com/) is the following:

                        "Driver={My SQL ODBC 3.51 Driver};Server= data.domain.com ;Port=3306;Data base=myDataBase ;User=myUsernam e; Password=myPass word;Option=3;"

                        Notice that no ODBC DSN name is provided in that string, yet (presumably) still works. Also, I'd verify that the name of the driver is correct "MySQL ODBC 3.51 Driver" - verify that in your ODBC manager, you may actually be using a different driver and consequently need to change this. The string you require is the same as the name of the driver you choose in the ODBC manager.

                        In my experience though, when you're using a DSN, you only need to specify something akin to:

                        "DataSource=MyD SN;User=MyUsern ame;Password=My Password;"

                        Any relevant DSN options for that driver where the defaults are required to be overridden would be appended to the end of that string with a semi-colon delimiter. If you specified all the required options when you configured the DSN, then your connectionstrin g could be as simple as:

                        "DataSource=MyD SN;"

                        Of course, think about security when you do things like this...obviousl y not having to specify a username and password when accessing a database is somewhat frivolous in most cases.
                        Hey balabaster,

                        Ok looking at the driver name it is "3.51.23" however changing the Driver string to Driver={MySQL ODBC 3.51.23 Driver} i get the error message
                        "ERROR [IM002][Mircrosoft][ODBC Driver Manager] Data source name not fond and no default driver specified"

                        So it would seem the driver 3.51 is the correct string to use?

                        Looking at connectionstrin gs.com and your suggestion that it should work even though the DSN isnt called seems to be the case. Removing the "Datasource=wam pmysqld;" from the connection string to resolves to the same error messages as before;
                        ExecuteNonQuery : Connecion property has not been initialized

                        ...sigh....

                        In ODBC DSN, should the File DSN be configured?

                        Thanks for you continued help with this.


                        Sy

                        Comment

                        • balabaster
                          Recognized Expert Contributor
                          • Mar 2007
                          • 798

                          #13
                          Originally posted by SyGC
                          Hey balabaster,



                          Ok looking at the driver name it is "3.51.23" however changing the Driver string to Driver={MySQL ODBC 3.51.23 Driver} i get the error message
                          "ERROR [IM002][Mircrosoft][ODBC Driver Manager] Data source name not fond and no default driver specified"

                          So it would seem the driver 3.51 is the correct string to use?



                          Looking at connectionstrin gs.com and your suggestion that it should work even though the DSN isnt called seems to be the case. Removing the "Datasource=wam pmysqld;" from the connection string to resolves to the same error messages as before;
                          ExecuteNonQuery : Connecion property has not been initialized

                          ...sigh....

                          In ODBC DSN, should the File DSN be configured?

                          Thanks for you continued help with this.


                          Sy
                          If you reference using "DSN=MyDSN" then you would need a DSN configured - it doesn't matter whether it's file, user or system. Obviously a user DSN is only visible to the user that created it, so if it needs to be system wide it would have to be either file or system. I favour system, but if you favour file, that's okay too. If you're referencing using the longer connectionstrin g (without the DSN specified) then you don't even need to configure an ODBC entry in the ODBC Configuration Manager.

                          In answer to the problem at hand though - You've not referenced the connection object in your command initialization.
                          Code:
                          Dim oCmd As New OdbcCommand("Drop Table MyTable;", oCon)
                          Notice in yours, that you only have
                          Code:
                          Dim oCmd As New OdbcCommand("Drop Table MyTable;")
                          Sorry, I should've picked that up earlier... but at least you've probably got a better understanding of ODBC while tracking through this...

                          Comment

                          • SyGC
                            New Member
                            • Feb 2008
                            • 17

                            #14
                            Originally posted by balabaster
                            If you reference using "DSN=MyDSN" then you would need a DSN configured - it doesn't matter whether it's file, user or system. Obviously a user DSN is only visible to the user that created it, so if it needs to be system wide it would have to be either file or system. I favour system, but if you favour file, that's okay too. If you're referencing using the longer connectionstrin g (without the DSN specified) then you don't even need to configure an ODBC entry in the ODBC Configuration Manager.

                            In answer to the problem at hand though - You've not referenced the connection object in your command initialization.
                            Code:
                            Dim oCmd As New OdbcCommand("Drop Table MyTable;", oCon)
                            Notice in yours, that you only have
                            Code:
                            Dim oCmd As New OdbcCommand("Drop Table MyTable;")
                            Sorry, I should've picked that up earlier... but at least you've probably got a better understanding of ODBC while tracking through this...

                            Hey balabaster,

                            Dont apologise! Its funny really. Whilst having no luck with the ODBC method i moved back to OLeDB and managed to get it to work!!!! Amazing what happens when you spend hours and hours researching the internet AND more importantly getting help from people such as yourself!

                            Code:
                             Dim SQLConnection As OleDbConnection
                                    Dim SQLInsertCMD As OleDbCommand
                            
                                    Dim sConnString As String = _
                                        "Provider=OleMySql.MySqlSource.1;" & _
                                        "Data Source= " + TextBox1.Text + ";" & _
                                        "Initial Catalog=airproductsipdb;" & _
                                        "User Id=[B]USERNAME[/B];" & _
                                        "Password=[B]PASSWORD[/B];"
                            
                                    SQLConnection = New OleDb.OleDbConnection(sConnString)
                            
                                    SQLConnection.Open()
                            
                                    'SQLInsertCMD = New OleDb.OleDbCommand("DROP TABLE siteaddresses ;")
                                   [U] SQLInsertCMD = SQLConnection.CreateCommand()[/U]
                                    [U]SQLInsertCMD.CommandText = "DROP TABLE test1 ;"[/U]
                                    SQLInsertCMD.ExecuteNonQuery()
                                    MsgBox("Query executed")
                            By including the command within the connection i got it to work.



                            But! Thanks to your last post i now can get the ODBC to work! The missing 'oCon' from the Odbc.OdbcComman d string resolved the issue. It would seem in both cases the resolution was the same :D


                            So a BIG thank you to you Balabastar!

                            However now i face another problem........ .........Which to choose! :P lol


                            Thanks again...i will be back to bug the community once more with further problems :P


                            Sy
                            Last edited by Plater; Mar 19 '08, 08:58 PM. Reason: removed username password

                            Comment

                            • balabaster
                              Recognized Expert Contributor
                              • Mar 2007
                              • 798

                              #15
                              Glad to help. Good luck with the other issues.

                              P.S. Now that you've broadcasted your database username/password to the world, you should change it ;o)

                              Comment

                              Working...