Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2005, 01:49 PM
Registered User
 
Join Date: Feb 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error Connecting to MySQL with ASP.Net

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:

Code:
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





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.Net Mysql Error Prabhakar_dt VB Components 0 September 25th, 2005 06:34 AM
Connecting to MySQL with VB .NET CFerthorney Pro VB.NET 2002/2003 1 October 23rd, 2003 04:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.