Subject: Error Connecting to MySQL with ASP.Net
Posted By: arovner Post Date: 4/27/2005 1:49:23 PM
I have a MySQL database which I am trying to use with ASP.Net.

I have a page which is supposed to send out emails to subscribers.
It is supposed to query the DB to get the information to email,
write that the email was sent to a log, and then update the DB so
that it does not send out the email again.

The first 2 steps happen, but the last step does not. when i run the
page, i get an error that says "System.InvalidOperationException:
Connection must be valid and open".

I am using the same connection information to connect to the DB each
time, so I am not sure why I am getting that error message.

The code for the function which updates the DB is:

Function update(ByVal em As String) As Boolean
        
        Dim strSQL As String = 
        "UPDATE TABLE SET COLUMN1 = 'True' WHERE COLUMN2 = " + em

        Dim conn As MySql.data.MysqlClient.MySqlConnection
        Dim da As MySql.data.MysqlClient.MySqlDataAdapter
        Dim cb As MySql.data.MysqlClient.MySqlCommandBuilder
        Dim connStr As String


        connStr = "server=SERVERNAME;user id=USERNAME;
         password=PASSWORD; database=DBNAME; pooling=false"
        conn = New MySql.data.MysqlClient.MySqlConnection(connStr)
        conn.Open()

        Dim myCommand As MySql.data.MysqlClient.MySqlCommand = New 
         MySql.data.MysqlClient.MySqlCommand(strSQL, conn)
        myCommand.CommandType = Data.CommandType.Text
        myCommand.ExecuteNonQuery()   'Execute the UPDATE query
        
        conn.Close()   'Close the connection
        Return True
    End Function


I have the statement conn.open() to open the connection,
I am not sure what would make it invalid, any help would be great.

Thanks,
arovner

Go to topic 29819

Return to index page 567
Return to index page 566
Return to index page 565
Return to index page 564
Return to index page 563
Return to index page 562
Return to index page 561
Return to index page 560
Return to index page 559
Return to index page 558