locked
SQLDataSource will not connect to MYSQL DB. RRS feed

  • Question

  • User249648003 posted

    Hi,

    I am trying to connect a Gridview to a MYSQL DB through a SQLDataSource. However, the SQLDataSource does not work or connect.  I get the following error when I try to test my query:

    Could not create connection

    Exception o type 'Microsoft.VisualStudio.Web.Data.InternalException' was thrown.

    I can connect to MYSQL DB from the code behind like this, therefor I must have the MYSQLConnectors working:

    Using myConnection As New MySqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString) ......

    But my SQLDataSource configured like this does not work.

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" providerName="MySql.Data.MySqlClient"
    ConnectionString="<%$ connectionStrings:ConnectionString %>"
    SelectCommand="SELECT [email] FROM [my_aspnet_membership] ">

    <SelectParameters>
    <asp:Parameter Name="email" />
    </SelectParameters>
    </asp:SqlDataSource>

    Please help?

    Saturday, June 6, 2015 3:55 AM

All replies

  • User269602965 posted

    Parameters are used to pass variable values to the select statement.. most often to a filtering WHERE clause...

    we call these parameters BIND variable on the database side of the application.

    In your example EMAIL is a COLUMN NAME, which is not a parameter value.

    Select name, phone, email from my_aspnet_membership where email = :email

    the :email is the call to the parameter you named parameter "email" in your pararmeter statement.

    The COLON symbol tells MySQL and Oracle SQL client... that is a BIND variable awaiting population with parameter value.

    To keep things separate from column names you might call your bind variable something else like bind_email or p_email 

    Also note when you have more than one parameter, they must be listed in the same order they are used.

    Saturday, June 6, 2015 8:06 PM
  • User2071915566 posted

    Have you figured this out.  I am having the exact same issue and it has nothing to do with parameters since I don't have any.

    Tuesday, August 2, 2016 2:25 PM
  • User269602965 posted

    Perhaps populating your Grid in Code Behind Form/Page instead of in the ASPX page using MS SQL style Tags will work.

    Thursday, August 4, 2016 10:31 PM
  • User2071915566 posted

    Perhaps you should answer the question.  We already know how to do it with code but are asking why we are getting the error using the SQLDataSource wizard.

    Wednesday, February 8, 2017 7:23 PM