Computing.Net > Forums > Web Development > asp.net web service and mysql

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

asp.net web service and mysql

Reply to Message Icon

Name: damiike
Date: May 10, 2006 at 22:44:02 Pacific
OS: xp
CPU/Ram: 512+
Product: custom
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: May 11, 2006 at 21:37:44 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: asp.net web service and mysql

how to connect mysql database in asp.net????? www.computing.net/answers/webdevel/how-to-connect-mysql-database-in-aspnet/4117.html

Create PHP Web service www.computing.net/answers/webdevel/create-php-web-service/925.html

ASP.Net, dynamically create button www.computing.net/answers/webdevel/aspnet-dynamically-create-button-/1849.html