473,396 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

OleDbConnection problem (VB.NET)

17
Hello,

Im trying to connect to a MySQL DB on my home network (testing purposes) using the following VB.NET code;
Expand|Select|Wrap|Line Numbers
  1.  
  2. Imports System.Data.OleDb
  3.  
  4.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  5.  
  6.         Dim SQLConnection As OleDbConnection
  7.         Dim SQLInsertCMD As OleDbCommand
  8.         Dim sConnString As String = _
  9.             "Provider=OleMySql.MySqlSource.1;" & _
  10.             "Data Source=192.168.1.121, 3306;" & _
  11.             "Initial Catalog=airproductsipdb;" & _
  12.             "User Id=USERNAME;" & _
  13.             "Password=PASSWORD"
  14.  
  15.         SQLConnection = New OleDb.OleDbConnection(sConnString)
  16.         SQLConnection.Open()
  17.  
  18.         SQLInsertCMD = New OleDb.OleDbCommand("DROP TABLE table ;")
  19.  
  20.     End Sub
  21.  
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...
Expand|Select|Wrap|Line Numbers
  1. SQL Execution Error
  2. Executed SQl statement: SELECT site_id, Gateway_IP, Sitename, SubentAddress, SubnetMask, BroadcastAddress FROM sitename
  3. Error Source: System.Data
  4. Error Message: MySQL OLE DB Provider has not been activated
  5.  
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 Images
File Type: jpg DB_Connection.jpg (22.1 KB, 612 views)
Mar 15 '08 #1
16 7165
balabaster
797 Expert 512MB
Try the connectionstring 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 connectionstring if it connected. If it didn't connect, you'll see it says "Nothing".
Mar 16 '08 #2
SyGC
17
Try the connectionstring 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 connectionstring 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"response when holding my mouse over the connection object....

Expand|Select|Wrap|Line Numbers
  1. ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=192.168.1.121;Port=3306;Database=airproductsipdb;User=USERNAME;Password=PASSWORD;Option=3;"
  2.  
  3. ConnectionTimeout = 15
  4. Container =  Nothing
  5. DataSource = ""
  6. Driver = ""
  7. ServerVersion = {"Invalid operation. The connection is closed."}
  8. Site = Nothing
  9. State = Closed{0}
  10.  
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......

Expand|Select|Wrap|Line Numbers
  1.  
  2. ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Datasource=wampmysqld;Server=192.168.1.121;Port=3306;Database=airproductsipdb;User=USERNAME;Password=PASSWORD;Option=3;"
  3.  
  4. ConnectionTimeout = 15
  5. Container =  Nothing
  6. Database = "airproductsipdb"
  7. DataSource = "192.168.1.121 via TCP/IP"
  8. Driver = "myodbc3.dll"
  9. ServerVersion = "5.0.45-community-nt"
  10. Site = Nothing
  11. State = Open{1}
  12.  
  13.  
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?

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim SQLInsertCMD As Odbc.OdbcCommand
  3. SQLInsertCMD = New Odbc.OdbcCommand("DROP TABLE table ;")
  4.  
  5.  

Thanks

Sy
Mar 16 '08 #3
balabaster
797 Expert 512MB
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"response when holding my mouse over the connection object....

Expand|Select|Wrap|Line Numbers
  1. ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=192.168.1.121;Port=3306;Database=airproductsipdb;User=USERNAME;Password=PASSWORD;Option=3;"
  2.  
  3. ConnectionTimeout = 15
  4. Container = Nothing
  5. DataSource = ""
  6. Driver = ""
  7. ServerVersion = {"Invalid operation. The connection is closed."}
  8. Site = Nothing
  9. State = Closed{0}
  10.  
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......

Expand|Select|Wrap|Line Numbers
  1.  
  2. ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Datasource=wampmysqld;Server=192.168.1.121;Port=3306;Database=airproductsipdb;User=USERNAME;Password=PASSWORD;Option=3;"
  3.  
  4. ConnectionTimeout = 15
  5. Container = Nothing
  6. Database = "airproductsipdb"
  7. DataSource = "192.168.1.121 via TCP/IP"
  8. Driver = "myodbc3.dll"
  9. ServerVersion = "5.0.45-community-nt"
  10. Site = Nothing
  11. State = Open{1}
  12.  
  13.  
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?

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim SQLInsertCMD As Odbc.OdbcCommand
  3. SQLInsertCMD = New Odbc.OdbcCommand("DROP TABLE table ;")
  4.  
  5.  

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)
Mar 16 '08 #4
SyGC
17
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 ...

Expand|Select|Wrap|Line Numbers
  1.  
  2.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  3.  
  4.         Dim SQLConnection As Odbc.OdbcConnection
  5.  
  6.         Dim SQLInsertCMD As OleDb.OleDbCommand
  7.  
  8.         Dim sConnString As String = _
  9.         "Driver={MySQL ODBC 3.51 Driver};" & _
  10.         "Datasource=wampmysqld;" & _
  11.         "Server=192.168.1.121;" & _
  12.         "Port=3306;" & _
  13.         "Database=airproductsipdb;" & _
  14.         "User=USERNAME;" & _
  15.         "Password=PASSWORD;" & _
  16.         "Option=3;"
  17.  
  18.         SQLConnection = New Odbc.OdbcConnection(sConnString)
  19.         SQLConnection.Open()
  20.  
  21.         SQLInsertCMD = New OleDb.OleDbCommand("DROP TABLE table ;")
  22.     End Sub
  23.  
  24.  
Ive attached some screen shots also of the MySQL Connector ODBC configuration. ...if that helps.


Sy
Attached Images
File Type: jpg Connector ODBC.JPG (59.7 KB, 528 views)
File Type: jpg Connector ODBC COnnect options.JPG (58.1 KB, 800 views)
File Type: jpg Connector ODBC test.JPG (60.6 KB, 530 views)
Mar 16 '08 #5
balabaster
797 Expert 512MB
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 ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  3.  
  4. Dim SQLConnection As Odbc.OdbcConnection
  5.  
  6. Dim SQLInsertCMD As OleDb.OleDbCommand
  7.  
  8. Dim sConnString As String = _
  9. "Driver={MySQL ODBC 3.51 Driver};" & _
  10. "Datasource=wampmysqld;" & _
  11. "Server=192.168.1.121;" & _
  12. "Port=3306;" & _
  13. "Database=airproductsipdb;" & _
  14. "User=USERNAME;" & _
  15. "Password=PASSWORD;" & _
  16. "Option=3;"
  17.  
  18. SQLConnection = New Odbc.OdbcConnection(sConnString)
  19. SQLConnection.Open()
  20.  
  21. SQLInsertCMD = New OleDb.OleDbCommand("DROP TABLE table ;")
  22. End Sub
  23.  
  24.  
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
Expand|Select|Wrap|Line Numbers
  1. SQLConnection = New Odbc.OdbcConnection(sConnString)
is where you're instantiating the connection - "instantiate: 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:

Expand|Select|Wrap|Line Numbers
  1. Dim sConString As String = _
  2. "Driver={MySQL ODBC 3.51 Driver};" & _
  3. "Datasource=wampmysqld;" & _
  4. "Server=192.168.1.121;" & _
  5. "Port=3306;" & _
  6. "Database=airproductsipdb;" & _
  7. "User=USERNAME;" & _
  8. "Password=PASSWORD;" & _
  9. "Option=3;"
  10.  
  11. Dim oCon As Oledb.OleDbConnection = New Oledb.OledbConnection(sConnString)
  12. Try
  13.   oCon.Open()
  14.   Dim oCmd As Oledb.OledbCommand = New OleDb.OleDbCommand("DROP TABLE table;")
  15.  
  16.   'This is the crucial line that you're missing
  17.   oCmd.ExecuteNonQuery() 'This will execute a query that doesn't require a response
  18.   ''If you require a response then you would use the commented out code block below:
  19.   'Dim oRdr As Oledb.OledbDataReader = oCmd.ExecuteReader()
  20.   'If oRdr.HasRows Then
  21.   ' While oRdr.Read
  22.   ' Dim sOut As String = oRdr("Field1")
  23.   '' etc...
  24.   ' End While
  25.   'End If
  26. Catch ex As Exception
  27.   MsgBox ex.Message
  28. Finally
  29.   oCmd.Dispose()
  30.   oCon.Close()
  31.   oCon.Dispose()
  32. End Try
Mar 16 '08 #6
SyGC
17
Okay, I'm understanding your code a little better now... the line of code
Expand|Select|Wrap|Line Numbers
  1. SQLConnection = New Odbc.OdbcConnection(sConnString)
is where you're instantiating the connection - "instantiate: 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:

Expand|Select|Wrap|Line Numbers
  1. Dim sConString As String = _
  2. "Driver={MySQL ODBC 3.51 Driver};" & _
  3. "Datasource=wampmysqld;" & _
  4. "Server=192.168.1.121;" & _
  5. "Port=3306;" & _
  6. "Database=airproductsipdb;" & _
  7. "User=USERNAME;" & _
  8. "Password=PASSWORD;" & _
  9. "Option=3;"
  10.  
  11. Dim oCon As Oledb.OleDbConnection = New Oledb.OledbConnection(sConnString)
  12. Try
  13.   oCon.Open()
  14.   Dim oCmd As Oledb.OledbCommand = New OleDb.OleDbCommand("DROP TABLE table;")
  15.  
  16.   'This is the crucial line that you're missing
  17.   oCmd.ExecuteNonQuery() 'This will execute a query that doesn't require a response
  18.   ''If you require a response then you would use the commented out code block below:
  19.   'Dim oRdr As Oledb.OledbDataReader = oCmd.ExecuteReader()
  20.   'If oRdr.HasRows Then
  21.   ' While oRdr.Read
  22.   ' Dim sOut As String = oRdr("Field1")
  23.   '' etc...
  24.   ' End While
  25.   'End If
  26. Catch ex As Exception
  27.   MsgBox ex.Message
  28. Finally
  29.   oCmd.Dispose()
  30.   oCon.Close()
  31.   oCon.Dispose()
  32. 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

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim sConnString As String = _
  3.         "Provider=OleMySql.MySqlSource.1;" & _
  4.         "Datasource=wampmysqld;" & _
  5.         "Server=192.168.1.121;" & _
  6.         "Port=3306;" & _
  7.         "Database=airproductsipdb;" & _
  8.         "User=USERNAME;" & _
  9.         "Password=PASSWORD;" & _
  10.         "Option=3;"
  11.  

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..

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  3.  
  4.         Dim SQLConnection As OleDb.OleDbConnection
  5.  
  6.         'Dim SQLInsertCMD As OleDb.OleDbCommand
  7.  
  8.         Dim sConnString As String = _
  9.         "Provider=OleMySql.MySqlSource.1;" & _
  10.         "Datasource=wampmysqld;" & _
  11.         "Server=192.168.1.121;" & _
  12.         "Port=3306;" & _
  13.         "Database=airproductsipdb;" & _
  14.         "User=USERNAME;" & _
  15.         "Password=PASSWORD;" & _
  16.         "Option=3;"
  17.  
  18.         SQLConnection = New OleDb.OleDbConnection(sConnString)
  19.  
  20.         Dim oCon As OleDb.OleDbConnection = New OleDb.OleDbConnection(sConnString)
  21.         Try
  22.             oCon.Open()
  23.             Dim oCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("DROP TABLE table;")
  24.  
  25.             'This is the crucial line that you're missing
  26.             oCmd.ExecuteNonQuery() 'This will execute a query that doesn't require a response
  27.             ''If you require a response then you would use the commented out code block below:
  28.             'Dim oRdr As Oledb.OledbDataReader = oCmd.ExecuteReader()
  29.             'If oRdr.HasRows Then
  30.             ' While oRdr.Read
  31.             ' Dim sOut As String = oRdr("Field1")
  32.             '' etc...
  33.             ' End While
  34.             'End If
  35.         Catch ex As Exception
  36.             MsgBox(ex.Message)
  37.         Finally
  38.             'oCmd.Dispose()
  39.             oCon.Close()
  40.             oCon.Dispose()
  41.         End Try
  42.     End Sub
  43.  

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

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  3.  
  4.         Dim SQLConnection As Odbc.OdbcConnection
  5.  
  6.         'Dim SQLInsertCMD As OleDb.OleDbCommand
  7.  
  8.         Dim sConnString As String = _
  9.         "Driver={MySQL ODBC 3.51 Driver};" & _
  10.         "Datasource=wampmysqld;" & _
  11.         "Server=192.168.1.121;" & _
  12.         "Port=3306;" & _
  13.         "Database=airproductsipdb;" & _
  14.         "User=USERNAME;" & _
  15.         "Password=PASSWORD;" & _
  16.         "Option=3;"
  17.  
  18.         SQLConnection = New Odbc.OdbcConnection(sConnString)
  19.  
  20.         Dim oCon As Odbc.OdbcConnection = New Odbc.OdbcConnection(sConnString)
  21.         Try
  22.             oCon.Open()
  23.             Dim oCmd As Odbc.OdbcCommand = New Odbc.OdbcCommand("DROP TABLE table;")
  24.  
  25.             'This is the crucial line that you're missing
  26.             oCmd.ExecuteNonQuery() 'This will execute a query that doesn't require a response
  27.             ''If you require a response then you would use the commented out code block below:
  28.             'Dim oRdr As Oledb.OledbDataReader = oCmd.ExecuteReader()
  29.             'If oRdr.HasRows Then
  30.             ' While oRdr.Read
  31.             ' Dim sOut As String = oRdr("Field1")
  32.             '' etc...
  33.             ' End While
  34.             'End If
  35.         Catch ex As Exception
  36.             MsgBox(ex.Message)
  37.         Finally
  38.             'oCmd.Dispose()
  39.             oCon.Close()
  40.             oCon.Dispose()
  41.         End Try
  42.     End Sub
  43.  
Whilst running this i get the error message 'ExecuteNonQuery: Connection property has not been initialized'

Thanks again,


Sy
Mar 16 '08 #7
balabaster
797 Expert 512MB
After your oCon.Open() line, add the line MsgBox(oCon.State.ToString) this should tell you if the connection to the database was actually opened successfully or not.
Mar 17 '08 #8
balabaster
797 Expert 512MB
Add the line:
MsgBox(oCon.State.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.
Mar 17 '08 #9
SyGC
17
Add the line:
MsgBox(oCon.State.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....'ExecuteNonQuery: 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
Mar 18 '08 #10
balabaster
797 Expert 512MB
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....'ExecuteNonQuery: 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 connectionstring. The standard .NET connectionstring to access a MySql database (at least according the http://www.connectionstrings.com/) is the following:

"Driver={MySQL ODBC 3.51 Driver};Server=data.domain.com;Port=3306;Database= myDataBase;User=myUsername; Password=myPassword;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=MyDSN;User=MyUsername;Password=MyPassw ord;"

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 connectionstring could be as simple as:

"DataSource=MyDSN;"

Of course, think about security when you do things like this...obviously not having to specify a username and password when accessing a database is somewhat frivolous in most cases.
Mar 18 '08 #11
SyGC
17
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 connectionstring. The standard .NET connectionstring to access a MySql database (at least according the http://www.connectionstrings.com/) is the following:

"Driver={MySQL ODBC 3.51 Driver};Server=data.domain.com;Port=3306;Database= myDataBase;User=myUsername; Password=myPassword;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=MyDSN;User=MyUsername;Password=MyPassw ord;"

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 connectionstring could be as simple as:

"DataSource=MyDSN;"

Of course, think about security when you do things like this...obviously 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 connectionstrings.com and your suggestion that it should work even though the DSN isnt called seems to be the case. Removing the "Datasource=wampmysqld;" 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
Mar 19 '08 #12
balabaster
797 Expert 512MB
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 connectionstrings.com and your suggestion that it should work even though the DSN isnt called seems to be the case. Removing the "Datasource=wampmysqld;" 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 connectionstring (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.
Expand|Select|Wrap|Line Numbers
  1. Dim oCmd As New OdbcCommand("Drop Table MyTable;", oCon)
Notice in yours, that you only have
Expand|Select|Wrap|Line Numbers
  1. 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...
Mar 19 '08 #13
SyGC
17
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 connectionstring (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.
Expand|Select|Wrap|Line Numbers
  1. Dim oCmd As New OdbcCommand("Drop Table MyTable;", oCon)
Notice in yours, that you only have
Expand|Select|Wrap|Line Numbers
  1. 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!

Expand|Select|Wrap|Line Numbers
  1.  
  2.  Dim SQLConnection As OleDbConnection
  3.         Dim SQLInsertCMD As OleDbCommand
  4.  
  5.         Dim sConnString As String = _
  6.             "Provider=OleMySql.MySqlSource.1;" & _
  7.             "Data Source= " + TextBox1.Text + ";" & _
  8.             "Initial Catalog=airproductsipdb;" & _
  9.             "User Id=USERNAME;" & _
  10.             "Password=PASSWORD;"
  11.  
  12.         SQLConnection = New OleDb.OleDbConnection(sConnString)
  13.  
  14.         SQLConnection.Open()
  15.  
  16.         'SQLInsertCMD = New OleDb.OleDbCommand("DROP TABLE siteaddresses ;")
  17.         SQLInsertCMD = SQLConnection.CreateCommand()
  18.         SQLInsertCMD.CommandText = "DROP TABLE test1 ;"
  19.         SQLInsertCMD.ExecuteNonQuery()
  20.         MsgBox("Query executed")
  21.  
  22.  
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.OdbcCommand 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
Mar 19 '08 #14
balabaster
797 Expert 512MB
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)
Mar 19 '08 #15
Plater
7,872 Expert 4TB
I made an attempt to edit all the posts (All that QUOTEing killed me, hehe) and remove the username and password. If I missed any let me know.

You should still change them though.
Mar 19 '08 #16
SyGC
17
I made an attempt to edit all the posts (All that QUOTEing killed me, hehe) and remove the username and password. If I missed any let me know.

You should still change them though.
Thanks Plater....very foolish of me indeed! Although the permissions set up for that username account are only granted to my local IP address etc. Still a change would be sensible.

Cheers guys,

Sy
Mar 23 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
1
by: Lilly | last post by:
Hi all. I'm really sorry for this post, I'm sure most of you will think it's a silly question, but the following doesn't work and I'm really new to ASP.NET: <%@ Page Language="C#" %> <%@...
9
by: Nathan Sokalski | last post by:
I am trying to connect to a Microsoft Access Database from my ASP.NET Application. I use the following code to create my connection string: cmdSelect.Connection = New...
0
by: Terry | last post by:
I am getting the following message back from ASP.NET. MDAC 2.8 is installed as is .NET Framework 1.1 with SP and security updates on a Win 2K Server. For some reason .NET is not recognizing that...
5
by: petro | last post by:
Hello all, My asp.net web application works on my machine but I get the following error on our test web server, There is only one oracle home on the test server. Does anyone know how to resolve...
4
by: BookerW | last post by:
I am not sure which forum I should post this on, but here is the problem. I have a front end web application(VB) on asp,net 1.1 framework. Inside of the code, I have the following lines to...
4
by: sck10 | last post by:
Hello, I am using the following in ASP.NET 2.0 VB using ADODB (which is working). I would like to convert this to csharp using ADO.NET. To build the connection, I am trying to convert: ...
2
by: YEW | last post by:
Hi, all I am new to ASP.NET. I am testing an example that inserts a record into an access database. But i have got an error when i browse the sample aspx page from IE 7. In the error the line...
0
by: bw171 | last post by:
Hopefully, I frame this problem/question correctly. I have some code written/updated in visual studio 2003. This code when setup on other machines where I have installed the Oracle 9i client, and...
1
by: =?Utf-8?B?Ym9va2VyQG1ndA==?= | last post by:
Hopefully, I frame this problem/question correctly. I have some code written/updated in visual studio 2003. This code when setup on other machines where I have installed the Oracle 9i client,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.