SqlDataSource together with MySql ?

Last post 08-24-2007 10:43 AM by nbop. 37 replies.

Sort Posts:

  • SqlDataSource together with MySql ?

    06-02-2007, 11:13 PM
    • Loading...
    • Zavod
    • Joined on 05-18-2007, 10:45 PM
    • Posts 18

    Hello. My host is GoDaddy, and I need some help. 

    First of all I need to know if it is possible to use SqlDataSource-component with a MySql-database.

    I do have MySQL Connector Net 5.0.3 installed and I did place the MySql.Data.dll in the bin-directory.
    Had to recompile that dll to accept another trustlevel or something so I did that.

    The conenctionstring I use look like this (from web.config):

     

     <add name="Conn" connectionString="Server=xxx.secureserver.net;Database=mydatabase;uid=myuserid;pwd=mypassword;" providerName="MySql.Data.MySqlClient"/>
     
     

    The SqlDataSource:

     

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Conn %>" SelectCommand="SELECT country,city,event,date FROM shows" ProviderName="<%$ ConnectionStrings:Conn.ProviderName %>"></asp:SqlDataSource>
     

     And now to my sweet little error:

     
     System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.


    [ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
    System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1372135
    System.Web.UI.WebControls.SqlDataSource.GetDbProviderFactory() +63...

    etc etc...
      

    This guy seem to be able to do it without problem:

    Filter A GridView After The Initial Bind

     

    Am I doing something wrong, is it something with GoDaddy, or is it simply not yet possible to use these features with MySql?

    (I code in C#)

    Thanks.

     


     

    Filed under: , ,
  • Re: SqlDataSource together with MySql ?

    06-03-2007, 7:26 AM

    The sql datasource is setup to use sql server only.  I have always connected to MySql databases with the mysql dot net connector via code

     

    http://dev.mysql.com/downloads/connector/net/5.0.html

  • Re: SqlDataSource together with MySql ?

    06-03-2007, 11:20 AM
    • Loading...
    • Zavod
    • Joined on 05-18-2007, 10:45 PM
    • Posts 18

    This is from the MSDN:

    By default, the SqlDataSource control works with the .NET Framework Data
    Provider for SQL Server, but SqlDataSource is not Microsoft SQL
    Server-specific. You can connect the SqlDataSource control with any database
    product for which there is a managed ADO.NET provider. When used with the
    System.Data.OleDb provider, the SqlDataSource can work with any OLE
    DB-compliant database. When used with the System.Data.Odbc provider, the
    SqlDataSource can be used with any ODBC driver and database, including IBM
    DB2, MySQL, and PostgreSQL.

    The reason I want to use SqlDataSource is because I want to filter the rows
    without having to ask the database every time.  And other nice features.


    Is this stuff so rare, or how come it seems noone knows about it?
    Im open for all suggestions about how to make gridview and mysql talk to eachother
    just like the sqldatasource would do.

  • Re: SqlDataSource together with MySql ?

    06-04-2007, 11:03 AM
    • Loading...
    • JoshWithrow
    • Joined on 09-25-2002, 3:00 PM
    • Smyrna, Delaware
    • Posts 231

    Actually, the SQLDataSource control is not MSSQL specific.  It just requires an ADO.NET provider.  Sometimes you have to provide a ProviderName property to the control, though.

     

    For instance, I use MyODBC in most of my apps just for consistancy, but I have to use the SqlDataSource control as follows:

     

     

    <asp:SqlDataSource ProviderName="System.Data.Obdc" ID="mySqlDataSource" runat="server"
    	ConnectionString ="Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=dbName;User=dbUser;Password=dbUserPass;Option=3;"
    	SelectCommand ="SELECT * FROM tblEntries"
    	DeleteCommand ="DELETE FROM tblEntries WHERE EntryNumber=?"
    	UpdateCommand ="UPDATE tblEntries SET Name=?, Email=?,
    	  Website=?, Message=?, WHERE EntryID=?">
    	<DeleteParameters>
    	  <asp:Parameter Name="EntryID" Type="String" />
    	</DeleteParameters>
    	<UpdateParameters>
    	  <asp:Parameter Name="EntryID" Type="String" />
    	  <asp:Parameter Name="Name" Type="String" />
    	  <asp:Parameter Name="Email" Type="String" />
    	  <asp:Parameter Name="Website" Type="String" />
    	  <asp:Parameter Name="Message" Type="String" />
    	</UpdateParameters>
    </asp:SqlDataSource>

      

    So in your case, the ProviderName would be System.Data.MySql if I'm not mistaken. 

    Josh Withrow
    Chief Technology Officer (CTO) / Chief Left Brain Geek

    LuckyDog Digital
    http://www.luckydogdigital.com
    CREATIVE SERVICES FOR YOUR GROWING BUSINESS
    Print Design, Web Sites, Logos & Corporate Identity,
    Corporate Photography, Video Production
  • Re: SqlDataSource together with MySql ?

    06-04-2007, 2:21 PM
    • Loading...
    • Zavod
    • Joined on 05-18-2007, 10:45 PM
    • Posts 18

    I first used ODBC without sqldatasource, but the rusult was lost db-connections all the time. Did some research and it looked like it was a common problem.

    And yes, I did use a providername on my sqldatasource like i wrote in my first post.

    providerName="MySql.Data.MySqlClient
    I did try your example though,JoshWithrow.
    What I get when I use it with providerName="MySql.Data.MySqlClient, is exactly the same as before "...provider may not be installed".
    If I dont use it, I get other errors saying that keywords isnt supported.
    Keyword not supported: 'driver'.
    Soon I give up..
  • Re: SqlDataSource together with MySql ?

    06-04-2007, 5:50 PM
    • Loading...
    • JoshWithrow
    • Joined on 09-25-2002, 3:00 PM
    • Smyrna, Delaware
    • Posts 231

    After a bit of research it seems that this may or may not still be an issue depending upon the version  you're using.  Read more (with a link to a fix) here:

    http://bugs.mysql.com/bug.php?id=16126
     

    Josh Withrow
    Chief Technology Officer (CTO) / Chief Left Brain Geek

    LuckyDog Digital
    http://www.luckydogdigital.com
    CREATIVE SERVICES FOR YOUR GROWING BUSINESS
    Print Design, Web Sites, Logos & Corporate Identity,
    Corporate Photography, Video Production
  • Re: SqlDataSource together with MySql ?

    06-04-2007, 7:11 PM
    • Loading...
    • Zavod
    • Joined on 05-18-2007, 10:45 PM
    • Posts 18

    Thank you, I had seen thyat page allready though. And I couldnt find any fix there that they said worked.

    Also it looks like its not for the connector-version I have. :/ Its for 5.0.2 

  • Re: SqlDataSource together with MySql ?

    06-05-2007, 1:53 AM
    • Loading...
    • JoshWithrow
    • Joined on 09-25-2002, 3:00 PM
    • Smyrna, Delaware
    • Posts 231

    You can probably apply the same principle to the current connector version.  Anywho, I think I've exhausted my attempts.  Good luck. 

    Josh Withrow
    Chief Technology Officer (CTO) / Chief Left Brain Geek

    LuckyDog Digital
    http://www.luckydogdigital.com
    CREATIVE SERVICES FOR YOUR GROWING BUSINESS
    Print Design, Web Sites, Logos & Corporate Identity,
    Corporate Photography, Video Production
  • Re: SqlDataSource together with MySql ?

    06-05-2007, 2:01 AM
    • Loading...
    • Zavod
    • Joined on 05-18-2007, 10:45 PM
    • Posts 18

     Yes I will try it out. Thanks for your attempts.

  • Re: SqlDataSource together with MySql ?

    06-06-2007, 7:25 PM
    • Loading...
    • Zavod
    • Joined on 05-18-2007, 10:45 PM
    • Posts 18

    Im not sure I understand exactly what the fix is. The download on that site is the Mysq.Data.dll I allready have installed and placed in the bin-folder of my site.

    The thread isnt really up to date either so maybe its the ordinary connector but an early version? Anyway I grabbed it and replaced my old Mysql.data with it.
    Same error.
     

    Or is the fix to add those lines of code in web.config? They even mentioned to add some lines into mashine.config, and how should I do that when its not a deticated server.

     
    Please someone help me out here, feels like im the first one to try get this mysql-thing working.
     

  • Re: SqlDataSource together with MySql ?

    06-20-2007, 7:59 PM
    • Loading...
    • Garen
    • Joined on 06-20-2007, 11:54 PM
    • Posts 5

    I had this problem and I noticed that after I put in a connection string in my Web.config that referred to the .dll like so:

       <add name="MySQL_Connector_Str"   connectionString="..." providerName="MySql.Data.MySqlClient"/>

    and then go to configure data sources with the wizards and pick connection strings from the drop-down list, it would NEVER show up.  Strangely, the ODBC one showed up just fine after installing the .NET connector. I wasted lots of time googling for an answer for this and never found one.  Then I noticed this:

     http://dev.mysql.com/downloads/visual-studio-plugin/index.html
     

    So I installed that, and after a reboot, the connection string for that .dll was recognized and I could use it just fine (without stuffing it in the \Bin directory too). Now I just add:

    using MySql.Data.MySqlClient;

    To my .cs sources and I can use all the native MySql* methods fine! 

    Hope that helps. 

  • Re: SqlDataSource together with MySql ?

    06-20-2007, 8:30 PM
    • Loading...
    • Zavod
    • Joined on 05-18-2007, 10:45 PM
    • Posts 18

    Hello, I installed the plugin at the same time as the dll. And I have no problem connecting to mysql. Its just with SqlDataSource i cant get it to work.

    So I gave up the SqlDataSource and are now using ObjectDataSource instead.

  • Re: SqlDataSource together with MySql ?

    06-20-2007, 8:38 PM
    • Loading...
    • Garen
    • Joined on 06-20-2007, 11:54 PM
    • Posts 5

     Ah OK.  I suspect then the problem is getting it to recognize the right metacharacter(s) for specifying new values.  There's a way to set it in web.config iirc so that it uses the usual "@" char, but otherwise the default might be "?" char.  I'll have to give it a try sometime.

  • Re: SqlDataSource together with MySql ?

    06-20-2007, 8:47 PM
    • Loading...
    • Zavod
    • Joined on 05-18-2007, 10:45 PM
    • Posts 18

    For parameters yes. But I suspect is was something with the needed assembly, factory and Godaddy.

  • Re: SqlDataSource together with MySql ?

    06-25-2007, 4:54 PM
    • Loading...
    • JoshWithrow
    • Joined on 09-25-2002, 3:00 PM
    • Smyrna, Delaware
    • Posts 231

    Garen:

     Ah OK.  I suspect then the problem is getting it to recognize the right metacharacter(s) for specifying new values.  There's a way to set it in web.config iirc so that it uses the usual "@" char, but otherwise the default might be "?" char.  I'll have to give it a try sometime.

     

     

    Would you mind explaining how to accomplish this?  I'm curious and must be googling the wrong thing. 

    Josh Withrow
    Chief Technology Officer (CTO) / Chief Left Brain Geek

    LuckyDog Digital
    http://www.luckydogdigital.com
    CREATIVE SERVICES FOR YOUR GROWING BUSINESS
    Print Design, Web Sites, Logos & Corporate Identity,
    Corporate Photography, Video Production
Page 1 of 3 (38 items) 1 2 3 Next >