First, we'll create a web app using Visual Studio 2008.
Create a web app dialog |
<connectionStrings> <add name="testConnectionString" connectionString="server=localhost;user id=root;database=test" providerName="MySql.Data.MySqlClient" /> </connectionStrings>
Here is how my SqlDataSource is configured now.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>" ProviderName="<%$ ConnectionStrings:testConnectionString.ProviderName %>" SelectCommand="select * from t1"></asp:SqlDataSource>
At this point you can hit F5 in VS and the web app will run and show you the data you specified in your query. However, if you deploy this application to a remote server that does not have Connector/Net installed then it will fail and you may see something like this:
What's going on? The first thing to understand is how the SqlDataSource connects to a data provider. If you refer back to our connection string you'll see the attribute providerName have the value 'MySql.Data.MySqlClient'. That is the invariant name of Connector/Net. However this name is not enough to locate the right assembly to load. This mapping is done in either the machine.config or web.config files. The Connector/Net installer makes the proper registrations in the machine.config file. Here is the DbProviderFactories section from my machine.config (I've omitted all entries but Connector/Net for brevity).
<system.data> <DbProviderFactories> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.2.1.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories> </system.data>
With this entry in machine.config then the system can match the invariant name to a fully qualified assembly name and also identify the client factory class that should be used. You can see that by examining the type attribute above.
So what do you do if you are deploying this app to a remote server that you can't install Connector/Net on? Simple. Add this registration to your web.config. Just drop it in right outside the system.web block like this:
<system.data> <DbProviderFactories> <clear/> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.2.1.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories> </system.data>
So why the <clear/> tag? You can't doubly add provider factories to the config system so if you have Connector/Net installed on your dev system and you register the provider factory in your web.config then you will be doubly adding them. The clear tag clears out all the provider factories pulled in from machine.config and then adds in yours. Now if you are mixing providers then you'll need to adjust this to your situation.
I hope this blog post has cleared up some of the reasons why people have working web apps on their dev systems but then are confused when it doesn't work after deploy.
Hi there, I have been following ramblings and I must say I tend to agree with your interesting post
ReplyDeleteSame with this really nice codes. thanks alot.
ReplyDeletethis the tutorial i need..
ReplyDeletethanks
great tutorial, thank you
ReplyDeleteThanks
ReplyDeleteYou are a real master, body!
ReplyDeleteThanks!
thanks for teaching this.its really useful.
ReplyDeleteThis is exactly what I was looking for. Thanks for sharing this great article! That is very interesting :) I love reading and I am always searching for informative information like this! You are bookmarked!
ReplyDeleteThx,
great - love it
ReplyDeletethank u very much
ReplyDeletelol
Thank you so much! I needed this and I've been searching for days!
ReplyDeleteThis is exactly what I was looking for. Thanks for sharing this great article! That is very interesting Smile I love reading and I am always searching for informative information like this! You are bookmarked!
ReplyDeleteThx,
This is really great.. I enjoy reading this articles.
ReplyDeleteConnector/Net 5.1 represents a change in how we package our products. Until now, we've shipped our core provider and the Visual Studio integration bits as separate downloads. This has become a bit of a problem. Often we would fix a bug that involved changing code both in the VS package and in the core provider. This provided a versioning problem where users would need to upgrade both products to see the benefit of the bug fix. To solve this, we've decided to discontinue Tools for Visual Studio as a separate product and have, instead, integrated it into a new Connector/Net installer. We hope this provides a better "out of box" experience for our users.
ReplyDeleteVery informative post..
ReplyDeleteOn Windows, installation is supported either through a binary installation process or by downloading a Zip file with the Connector/NET components.
ReplyDeleteBefore installing, you should ensure that your system is up to date, including installing the latest version of the .NET Framework.
Heya - Just looking through some blogengine.net blogs, seems to be a fairly nice platform, certainly better than blogger but still playing with the idea of wordpress. Any major plus points you have found over WP at all?
ReplyDeleteThanks
Matthew
MySQL Connector/NET runs on any platform that supports the .NET framework. The .NET framework is primarily supported on recent versions of Microsoft Windows, and is supported on Linux through the Open Source Mono framework developed by Novell
ReplyDeletegreat
ReplyDeletethank u sir
love it all
Net Connector works invisibly to open the connection for you, ... When client caching is used, the client machine contains a local memory cache and a local ... It allows you to use three different types to connect to remote computer. ...
ReplyDeletethanks for sharing this.its really useful.
ReplyDeleteThats really something i didnt knew about. thanks
ReplyDeleteI am trying to install Acquia Drupal on Windows Server 2003 SP2. I am getting the message
ReplyDeleteMySQL Connector/Net 5.2
This product did not install successfully. Fatal error during installation.
i was looking for this for so many days.thank you!
ReplyDeleteOn Windows, installation is supported either through a binary installation process or by downloading a Zip file with the Connector/NET components.
ReplyDeleteI am trying to install Acquia Drupal on Windows Server 2003 SP2. I am getting the message
ReplyDeleteMySQL Connector/Net 5.2
This product did not install successfully. Fatal error during installation.
I'm not such an asp'er myself, but i find this very usefull. Thnaks!
ReplyDeleteIt's interesting, the blog engine platform seems very variable in form. My design skills are not so good as my C coding though, I would be interested in seeing what additional skins you can get for it. Nice blog btw, best wishes for it and keep up the posts. :) Kind regards, Peter sims.
ReplyDeleteMySql.Web acctualy creates the database structure. So the reson we could not log in is because there were no users in the database.
ReplyDeleteThis sample assumes you have a recent build of Connector/Net installed with Visual Studio integration enabled.
ReplyDeleteI read the articles and all the things here inside this blog .,I got many information that
ReplyDeleteI really need .,Thanks for sharing.,
Its quite easy to understand through this tutorial..
ReplyDeletegood tutorial, make it easier to understand
ReplyDeleteDescriptive and clear post, easy to understand.
ReplyDelete<a href="http://www.bestweddingdresses.net">Wedding Dresses</a>
I am quite interesting in this topic hope you will elaborate more on it in future posts.
ReplyDeleteGood post, I will mention it on my blog.. Cheers
ReplyDelete10x for the code :) Cheers!
ReplyDeleteNice way of summing it up.. cheers
ReplyDeleteyeah! you gotta big mind to think!
ReplyDeleteYou are so true on that! http://www.mrstiff.com
ReplyDeleteGive us many informations please?
ReplyDeletelouis vuitton handbags
Now this is hghly recommeded post for me. I will surely email this to my friend.
ReplyDeleteRegards
Matthews
I posted your blog to my facebook group
ReplyDeleteRegards
hanitz
I added your post to my college Report
ReplyDeleteRegards
saniths
that;s true...
ReplyDeletethat;s really useful
ReplyDeleteI digged this for more news from you.
ReplyDeleteRegards and respect
realman
I don’t think that all the articles will remain in the mind without missing a single word whichever we read. I think this article done a great job.What a best way to describe your view. Thanks for sharing with us. Really like your informative article.
ReplyDeleteHopefully we will get more interesting topic from you in future.
Thanks for sharing this cool stuffs.
ReplyDeletelouis vuitton handbags
I try to connect MySQL via sqlDataSource. I use VWD 2008 Express, MySQL 5.0.87-community-nt and MySQL Connector/Net 6.2.2. In my web project, I not find MySQL Database in Data Source. Why! Help me!
ReplyDeleteRight now we don't integrate into Visual Web Developer. This is something we are trying to fix
ReplyDeleteI'm trying to use the newest version of the Connector/Net on GoDaddy. I've followed you instructions and also read other posts that link to this one. I'm still getting:
ReplyDeleteParser Error Message: Unable to initialize provider. Missing or incorrect schema.
Does it matter which version of the provider I use as long as I put the correct MySql.Data.dll and MySql.Web.Dll in the App_Code and/or /Bin dirs?
No, it doesn't matter as long as the version you use serves your needs. Are you using the 'autogenerateschema=yes' option? Did you use the wizard to set it up?
ReplyDelete