Print Page | Close Window

Connecting a .net webservice to MySQL

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=25586
Printed Date: 28 March 2026 at 4:39pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Connecting a .net webservice to MySQL
Posted By: kfa
Subject: Connecting a .net webservice to MySQL
Date Posted: 10 April 2008 at 12:07pm
I have created a MySQL database on the server and want to connect through a .net web service written in C#. It works on my local computer using a MySQL Connector assembly, but this obviously doesn't work on the server. I guess it's not installed on the server, but then what?
 
Can anyone please give me an example of how to connect to a MySQL database in C#? Especially what using directives are required?
 
Thanks in advance!



Replies:
Posted By: jamie.townsend
Date Posted: 10 April 2008 at 1:12pm
Hey, who is your hosting provider ?

Some hosting providers block third party class libaries so you may struggle with some.
Have you tried using myodbc ?


Posted By: kfa
Date Posted: 10 April 2008 at 1:25pm
Thanks for your reply.
 
It's hosted here at Webwiz Hosting. I just can't seem to find any documentation on how to setup the connection.
 
No, I haven't tried with myODBC, but I suppose it works similar to the MySQL Connector. Am I supposed to upload an assembly dll with one of the drivers mentioned, or does Webwiz hosting have some kind of connection driver installed, which I can use?
 
I'm quite new to this, so any help will be appreciated, thanks :-)


Posted By: WebWiz-Bruce
Date Posted: 10 April 2008 at 1:28pm
mySQL not does work very well with mySQL although Microsoft are presently working on a driver to address this issue.

You should instead use SQL Server with ASP.NET as they are designed to work together and would give you much better performance and as all hosting packages come with SQL Server databases there is no reason to use mySQL with ASP.NET which I would suggest avoiding.


-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: kfa
Date Posted: 10 April 2008 at 1:50pm
Bruce, did you mean "does NOT work very well"?
 
The reason why I want to use mySQL is that I'm working on a university project and we want the solution to be as platform independent as possible. Is there no possible way to connect to mySQL on the webwiz server? And in that case why are you offering mySQL databases?
 
Thanks again..


Posted By: WebWiz-Bruce
Date Posted: 10 April 2008 at 2:53pm
mySQL is not normally used with ASP.NET but it is used with other supported technologies such as PHP and ASP. Although for ASP I would still recommend using SQL Server.

You can use the myODBC 3.51 driver which is installed on the servers to connect using ASP.NET.

A quick search on Google found the following page:-

http://www.freevbcode.com/ShowCode.asp?ID=6187

But you should be able to find other examples.


-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: kfa
Date Posted: 11 April 2008 at 3:04pm
Thanks for your reply.
 
I've downloaded myODBC 3.51 from http://www.mysql.com - www.mysql.com . Now I'm just trying to get it to work on my own computer in my asp.net application (which is in C# btw).
 
Is it correct that ODBC should be able to connect both to a mySQL or an MSSQL database?
And is 'System.Data.Odbc' the only using directive needed to be able to connect?


Posted By: WebWiz-Bruce
Date Posted: 12 April 2008 at 4:17pm
With SQL Server you should use the OLE driver it's much faster than ODBC.

Using different databases isn't as simple as just using ODBC. mySQL and SQL Server are very different and use different data types and different SQL.

mySQL is very good if you are using PHP, but in your case you should be using SQL Server with ASP.NET as this is ASP.NET's native database.

Using mySQL and ASP.NET would not give you the platform independence you are looking for but will give you no end of problems trying to get the two to work successfully together.


-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: kfa
Date Posted: 12 April 2008 at 5:21pm
Allright, I gave the myODBC a try in order to connect to MySQL, but I got this error:
 
System.Security.SecurityException: Request for the permission of type 'System.Data.Odbc.OdbcPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
 
It works perfectly on my own computer, but not on the Webwiz server. I googled the error message, and it seems to be something about trust levels? Have no clue what to do about it. I'm not quite sure about my connection string though, it looks like this:

"DRIVER={MySQL ODBC 3.51 Driver};SERVER=mysql.webwiz.net;PORT=3306;DATABASE=myDatabase;UID=myUsername;PASSWORD=myPassword;OPTION=3"

Does my connection string look right, or can anybody point out what's wrong? If there is no simple way to solve this problem, I will probably skip mySQL and go for the SQL Server instead...




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net