473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

C# and MySQL

Ook
Has anyone sucessfully connected a C# asp form to a MySQL database? If so,
would you care to share how you did it?
Nov 15 '05 #1
6 2654
Ook,

If your ASP page is running on a different machine than the MySQL
database, then by default, you won't be able to connect. The reason for
this is that ASP.NET pages by defualt run under the local ASPNET user
account, which has limited rights. It doesn't have the right to open
network connections.

What you need to do is impersonate a user that has rights to the
database either through modification of the web.config file in the directory
the page is located, or by calling the Impersonate method on the
WindowsIndentity class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ook" <outlookexpress@nospam@embertsdotcom> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
Has anyone sucessfully connected a C# asp form to a MySQL database? If so,
would you care to share how you did it?

Nov 15 '05 #2
Ook
OK, now I'm confused :)

This application will be used by 50 users each sitting at their own
workstation. The MySQL database is sitting on yet another machine. Is this
not something that is easily done with c#?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:u3**************@TK2MSFTNGP10.phx.gbl...
Ook,

If your ASP page is running on a different machine than the MySQL
database, then by default, you won't be able to connect. The reason for
this is that ASP.NET pages by defualt run under the local ASPNET user
account, which has limited rights. It doesn't have the right to open
network connections.

What you need to do is impersonate a user that has rights to the
database either through modification of the web.config file in the directory the page is located, or by calling the Impersonate method on the
WindowsIndentity class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ook" <outlookexpress@nospam@embertsdotcom> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
Has anyone sucessfully connected a C# asp form to a MySQL database? If so, would you care to share how you did it?


Nov 15 '05 #3
Ook,

The application will be accessed through a browser of some sort, and the
code that actually does the accessing of the database is going to reside on
a server that the users connect to. You have to make sure that the process
that it runs under (the code accessing the database) has the appropriate
access rights. By default, ASP.NET does not (you mentioned an ASP form).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ook" <outlookexpress@nospam@embertsdotcom> wrote in message
news:uO**************@TK2MSFTNGP10.phx.gbl...
OK, now I'm confused :)

This application will be used by 50 users each sitting at their own
workstation. The MySQL database is sitting on yet another machine. Is this
not something that is easily done with c#?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:u3**************@TK2MSFTNGP10.phx.gbl...
Ook,

If your ASP page is running on a different machine than the MySQL
database, then by default, you won't be able to connect. The reason for
this is that ASP.NET pages by defualt run under the local ASPNET user
account, which has limited rights. It doesn't have the right to open
network connections.

What you need to do is impersonate a user that has rights to the
database either through modification of the web.config file in the

directory
the page is located, or by calling the Impersonate method on the
WindowsIndentity class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ook" <outlookexpress@nospam@embertsdotcom> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
Has anyone sucessfully connected a C# asp form to a MySQL database? If so, would you care to share how you did it?



Nov 15 '05 #4
Comments inline:

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:u3**************@TK2MSFTNGP10.phx.gbl...
Ook,

If your ASP page is running on a different machine than the MySQL
database, then by default, you won't be able to connect. The reason for
this is that ASP.NET pages by defualt run under the local ASPNET user
account, which has limited rights. It doesn't have the right to open
network connections.
Huh? Are you sure about this? I can't test this right now but I doubt this
is the case.
What you need to do is impersonate a user that has rights to the
database either through modification of the web.config file in the directory the page is located, or by calling the Impersonate method on the
WindowsIndentity class.
I've written an ASP.NET web app that connects to an MySQL database using the
ByteFX driver (http://www.bytefx.com/). The programming model is practically
identical to that of SqlClient, just the class names are different. There is
no need for impersonation, you just set up the database connection string as
usual.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ook" <outlookexpress@nospam@embertsdotcom> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
Has anyone sucessfully connected a C# asp form to a MySQL database? If so, would you care to share how you did it?


Nov 15 '05 #5
Sami,

If your server is on the same machine as IIS is, then you will not have
a problem with this. However, if the MySql server is not the IIS machine,
then you will have to establish a network connection. The default settings
of an ASP.NET page prevent this from ocurring, and this is a common issue
with people using ASP.NET that are unaware of the security settings in it.

To get around it, you have to do what I said (configure impersonation in
web.config, or make a call in the page itself) so that you obtain rights to
access another machine in the network.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sami Vaaraniemi" <sa***************@jippii.fi> wrote in message
news:bs**********@phys-news1.kolumbus.fi...
Comments inline:

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:u3**************@TK2MSFTNGP10.phx.gbl...
Ook,

If your ASP page is running on a different machine than the MySQL
database, then by default, you won't be able to connect. The reason for
this is that ASP.NET pages by defualt run under the local ASPNET user
account, which has limited rights. It doesn't have the right to open
network connections.
Huh? Are you sure about this? I can't test this right now but I doubt this
is the case.
What you need to do is impersonate a user that has rights to the
database either through modification of the web.config file in the

directory
the page is located, or by calling the Impersonate method on the
WindowsIndentity class.


I've written an ASP.NET web app that connects to an MySQL database using

the ByteFX driver (http://www.bytefx.com/). The programming model is practically identical to that of SqlClient, just the class names are different. There is no need for impersonation, you just set up the database connection string as usual.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ook" <outlookexpress@nospam@embertsdotcom> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
Has anyone sucessfully connected a C# asp form to a MySQL database? If so, would you care to share how you did it?



Nov 15 '05 #6

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eV**************@TK2MSFTNGP10.phx.gbl...
Sami,

If your server is on the same machine as IIS is, then you will not have a problem with this. However, if the MySql server is not the IIS machine,
then you will have to establish a network connection. The default settings of an ASP.NET page prevent this from ocurring, and this is a common issue
with people using ASP.NET that are unaware of the security settings in it.


Odd. My machine.config specifies userName="machine" (so its the
low-privilege account), and my app's web.config specifies no impersonation.
Further, if my web app tries to e.g., write to the event log, it fails with
a SecurityException as expected. Yet my web application is successfully
calling the google web service, which does establish a network connection.
If what you are saying is true, then the web service call should fail too
shouldn't it?

You're right about my database, it's local. But if my memory serves me in
the previous project I worked on I was calling a remote SQL database from a
low-privilege ASPNET account with no impersonation. I guess I'm just going
to have to try this out.

Sami
Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: francescomoi | last post by:
Hi. I'm trying to build 'MySQL-python-1.2.0' on my Linux FC2: ---------------------------------- # export PATH=$PATH:/usr/local/mysql/bin/ # export mysqlclient=mysqlclient_r # python setup.py...
4
by: mikey | last post by:
Hi all, I'm having great problems trying to install the latest MySQl RPM package onto my Red Hat Linux OS. There is already MySQL v 3.0 pre-installed with the RH Linux distribution disk but I...
0
by: Yun Guan | last post by:
Hello mysql gurus, I am trying to run perl on mysql database on Red Hat box. I want to install DBI and DBD:mysql using CPAN: perl -MCPAN -e shell cpan>install DBI The above succeeded, but...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
2
by: Saqib Ali | last post by:
I installed mySQL and have it running.... but I think I made a mistake somewhere along the line...... I believe I did follow the instructions that were provided with the distribution at:...
1
by: Alex Hunsley | last post by:
I am trying to install the DBD::mysql perl module. However, it claims I need mysql.h: cpan> install DBD::mysql CPAN: Storable loaded ok Going to read /home/alex/.cpan/Metadata Database was...
0
by: ./Rob & | last post by:
Hi gang: I'm experiencing a problem with MySQL -- I updated MySQL from version 4.1.0 to 4.1.10 and now when I login as root it doesn't show all the databases I should have access to, nor it...
2
by: trihanhcie | last post by:
I m currently working on a Unix server with a fedora 3 as an os My current version of mysql is 3.23.58. I'd like to upgrade the version to 5.0.18. After downloading from MYSQL.COM the package on...
1
by: manish deshpande | last post by:
Hi, When i'm installing MySQL-server-standard-5.0.24a-0.rhel3.i386.rpm by the following command: rpm -i MySQL-server-standard-5.0.24a-0.rhel3.i386.rpm the following error is being shown: ...
3
by: menzies | last post by:
Hi, I"m new to this forum, but I have been trying all day to install DBD::mysql onto my Intel MacBook. I've read lots of forums pages and none have gotten me to a successful 'make test' or a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.