Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 726171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:25:18+00:00 2026-05-14T06:25:18+00:00

NET and VB.net code behind. I have a classic ASP page that connects to

  • 0

NET and VB.net code behind. I have a classic ASP page that connects to the mySQL server with the following code:

 Set oConnection = Server.CreateObject("ADODB.Connection")
 Set oRecordset = Server.CreateObject("ADODB.Recordset")

 oConnection.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=example.com; PORT=3306;      DATABASE=xxx; USER=xxx; PASSWORD=xxx; OPTION=3;"
 sqltemp = "select * from userinfo WHERE emailAddress = '" & theUN & "'"
 oRecordset.Open sqltemp, oConnection,3,3

 if oRecordset.EOF then
 ...

However, i am unable to find anything to connect to mySQL in ASP.NET (VB.NET). I have only found this peice of code that does not seem to work once it gets to the “Dim conn As New OdbcConnection(MyConString)” code:

 Dim MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver};" & _
 "SERVER=example.com;" & _
 "DATABASE=xxx;" & _
 "UID=xxx;" & _
 "PASSWORD=xxx;" & _
 "OPTION=3;"

 Dim conn As New OdbcConnection(MyConString)
 conn.Open()

 Dim MyCommand As New OdbcCommand
 MyCommand.Connection = MyConnection
 MyCommand.CommandText = "select * from userinfo WHERE emailAddress = '" & theUN & "'""
 MyCommand.ExecuteNonQuery()
 MyConnection.Close()

I have these import statements also:

 <%@ Import Namespace=System %>
 <%@ Import Namespace=System.IO %>
 <%@ Import Namespace=System.Web %>
 <%@ Import Namespace=System.ServiceProcess %>
 <%@ Import Namespace=Microsoft.Data.Odbc %>
 <%@ Import Namespace=MySql.Data.MySqlClient %>
 <%@ Import Namespace=MySql.Data %>
 <%@ Import Namespace=System.Data %>

The error is as follows:

Compiler Error Message: BC30002: Type ‘OdbcConnection’ is not defined.

Source Error:

 Line 121:  "OPTION=3;"
 Line 122:  
 Line 123:  Dim conn As New OdbcConnection(MyConString) '<--error line
 Line 124:  conn.Open()
 Line 125:  

So any help would be great! :o)

EDIT: GOT IT WORKING USING THIS WAY

 Dim MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver};" & _
 "SERVER=example.com;" & _
 "DATABASE=xxx;" & _
 "UID=xxx;" & _
 "PASSWORD=xxx;" & _
 "OPTION=3;"

 Dim conn As OdbcConnection = New OdbcConnection(MyConString)
 conn.Open()

 Dim MyCommand As New OdbcCommand
 MyCommand.Connection = conn
 'MyCommand.CommandText = "INSERT INTO tablename VALUES("val1","val2","val3")"
 'MyCommand.ExecuteNonQuery()
 conn.Close()

AND WITH THE mysql.data.DLL IN PLAY

 Dim MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver};" & _
    "SERVER=example.com;" & _
    "DATABASE=xxx;" & _
    "UID=xxx;" & _
    "PASSWORD=xxx;" & _
    "OPTION=3;"

    Dim conn As New MySqlConnection(MyConString)
    conn.Open()

    Dim MyCommand As New MySqlCommand
    MyCommand.Connection = conn
    'MyCommand.CommandText = "INSERT INTO tablename VALUES("val1","val2","val3")"
    'MyCommand.ExecuteNonQuery()
    conn.Close()

David

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:25:18+00:00Added an answer on May 14, 2026 at 6:25 am

    1) Get the newest connector from the MySQL site

    2) From what they give you, copy the MySql.Data.dll to your Bin folder for your web app

    3) Add this line to your code-behind at the top:

    Imports MySql.Data.MySqlClient
    

    4) Use this code, updating the all-caps portions of the connection string:

        Using Con As New MySqlConnection("Database=DB;Server=SERVER-NAME;User Id=USERNAME;Password=PASSWORD;ignore prepare=false")
            Con.Open()
            Using Com As New MySqlCommand("select * from userinfo WHERE emailAddress=?emailAddress", Con)
                Com.CommandType = Data.CommandType.Text
                Com.Parameters.AddWithValue("?emailAddress", theUN)
                Using RDR = Com.ExecuteReader()
                    If RDR.HasRows Then
                        Do While RDR.Read
                            'Do stuff here
                            Response.Write(RDR.Item("emailAddress").ToString())
                        Loop
                    End If
                End Using
            End Using
            Con.Close()
        End Using
    

    Edit

    The ? syntax is to avoid SQL injection, you could concatenate instead, too

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a line of C# in my ASP.NET code behind that looks like
I have ASP.Net code similar to the following (this is inside a FIELDSET): <ol>
ASP.Net: In code-behind I can simulate <%# Eval(Property)%> with a call to DataBinder.Eval(myObject,Property); How
Why are the code-behind pages for an ASP.NET web application locked at run time?
What is the purpose of the code behind view file in ASP.NET MVC besides
(Was: ASP.Net codebehind not finding controls on the web page) I'm using VS 2008.
I am about to add a section to an ASP.NET app (VB.NET codebehind) that
I am using a codebehind page in ASP.NET to perform a SQL query. The
I thought .Net code gets compiled into MSIL, so I always wondered how do
Here is a VB.NET code snippet Public Class OOPDemo Private _strtString as String Public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.