Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi I am wondering if anyone can resolve this issue, as it is of great urgence.
I have a webservice that is being hosted on godaddy, windows box, mysql 4.24, asp.net v1.1,
i have setup a web service on the godaddy hosting, using the virtual directory, and tested it, so i know it works.
i have setup the database in mysql, and all the sql statements have been tested.
i have the following code in the service, when a method is invoked.
here is the code for the connection:
Dim connectionString As String = "Server='mysql21.secureserver.net';Port='3306';Database='dbname';Uid='dbuid';Pwd='dbpwd'"
Dim databaseConnection As MySqlConnection = New MySqlConnection(connectionString)
Dim command As MySqlCommand = New MySqlCommand("SELECT * FROM supplier WHERE supplier_id = '" & "'1'", databaseConnection)
command.Connection.Open()
Dim dr As MySqlDataReader
dr = command.ExecuteReader()
command.Connection.Close()
Return dr("supplier_id").ToString()now as you can see the connection is open and is then executing the query, the connection is also connecting to the database fine...
however when i invoke this code this is the error that is being caught on the execution of the sql statement...Error Caught: System.InvalidOperationException: Connection must be valid and open
at MySql.Data.MySqlClient.MySqlCommand.CheckState()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
at SecondChildhoodWebService.SecondChildhoodWebService.HelloWorld()
all help is much appreciated fellas n ladies,cheers,
miike

It looks pretty good to me...I connect fine to mysql in a .NET application, but my connection string looks a bit different:
ConnectionString = "SERVER=localhost;user id=uidhere;password=pwhere;database=dbname;pooling=false;";
Also, I always open the connection before I send it to the command object...I wouldn't think that would make a difference, but you might as well try. IMHO, It makes things a bit more clear when you open/close the connection via the original variable and not through Command.Connection.
I would try putting a statement to print databaseConnection.ConnectionState.ToString() somewhere so you can see what the state really is when you execute reader.
Good luck,
-SN

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |