MySql database connection issue - c#

I have an ASP.NET application, that connects to a mysql database. If on the server I run the web site in visual studio (which uses development server), it can connect to the mysql database correctly.
However, if on that same server I use IIS, an exception 'Unable to connect to any of the specified MySQL hosts' is thrown. It is configured to use an application pool with identity as 'ApplicationPoolIdentity'.
Connection string is like:
<add name="MYSQLConnectionString" connectionString="uid=name;server=111.11.111.111;Pwd=password;database=dbname" providerName ="MySql.Data.MySqlClient"/>
What could be the problem?

When your debugging with Visual Studio the account is local admin and has rights to everything most likely. The IIS default application pool account does not have these elevated privileges. Make sure the account that your IIS site application pool is running under has the correct permissions, or temporarily change the account to be local system to see if it is a permssions related issue. You can use FileMon to trace what files or registry entries the default account is having trouble accessing.
[EDIT]
Most likely you installed MySQL to someplace like C:\MySQL and you just need to grant the IIS application pool account read access to that directory, and possibly a registry entry or two.

The site was not installed in the root, but as an application in the default web site. If we run it as the root site, it works. Don't know why exactly though.

Related

How to find out which user web app is running as?

I'm using HttpPostedFile.SaveAs() in a Web API app. It fails to save with an access denied error if the file already exist.
From this post HttpPostedFileBase.SaveAs method question, that should not be the case. If I manually delete the file, all is well.
Is this issue related to permissions?
When I look in Explorer at the users who have permissions on this folder, there are four. Only my user doesn't have write permissions. I don't think that is the issue because otherwise, I wouldn't be able to write at all correct?
This is running on my dev machine.
It depends if the web app is running under IIS or IIS Express.
If your'e running from visual studio by default it on IIS Express, in that case the user is the user which ran Visual Studio (you). Be sure to run VS as administrator.
Under IIS the user is determand by the user running the Application pool which the app is attached to. By default a new special user is created for you which be named after the app-pool. You may change it at:
IIS-> Application Pool -> Right click the correct apppool -> advanced -> change the identity.
The easyest way to find out the actual user is to look at windows Task Manager (ctrl+shift+esc), go to Details, look for w3wp.exe and look at the username.

Error. An error occurred while processing your request

Fairly simple question about connection strings using an ASP.Net MVC web application with a SQL server Database.
I created a Web application which uses a database, using the default templates for an MVC 5 application using Visual studio 2014.
I am moving my application over to a IIS and sql server express database (2014) and I see that the database my application uses is a localDB (has a .mdf extension) what I need to know is how to attach it to my SQL Server Express database. (The development Machine and the Server are separate machines)
I have attached it to the server and have a login "IIS APPPOOL\DefaultAppPool" for my IIS to be able to use the server. Here I have granted the login read and write permission to the database "aspnet-owinTest-20140519094353" and my connection string in IIS is
Server=KEVIN-PC\SQLEXPRESS;Database=aspnet-owinTest-20140519094353;Integrated Security=true
The default connection string when building my application is:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-owinTest-20140519094353.mdf;Initial Catalog=aspnet-owinTest-20140519094353;Integrated Security=True" providerName="System.Data.SqlClient" />
If anyone can please give me a hand with this. My application simply throws an error
Error.
An error occurred while processing your request.
This is the default MVC error.
Also are there any ways where I can see what happened? As in a log of sorts, I checked in the IIS log and there did not seem to be any information that would help me. Would it be better for me to just have a login that used a Username/Password rather than using Windows Authentication?
I believe I found what I was looking for:
How to deploy ASP.NET MVC 4 application using localDB to local IIS on Windows 7?
This did the trick, though probably not a good idea for production server.
I guess one would have to do some type of restore on the SQL server from the .mdf.
All one has to do is publish their files, drop them in the wwwroot folder (along with the app_data folder containing your database and logs) and set the pool to local and you should be set.
If you are quite new to Visual Studio and facing this error, the very first thing I would suggest to check is INCLUDE all the files from the project. If there are some dependent folders or files which are left as excluded, this very error message is thrown back to browser.
To do this, first click on the icon of "Show All Files" and check for any of the expected files which you created/added but didn't include in the project. If you find one, then right click and include it.
If there is any quicker way to identify/avoid any such excluded files/folders issues, then please share below in comments.

How can I run an ASP.NET website globally [or atleast in my LAN]

I made a site using VS10 Ultimate [ASP.NET] and when I build & run it runs the severer locally, while I want to test it for security issues via Linux.
How can I run it globally ?
Thank you!
Your development machine probably has IIS installed. Copy the code or the compiled code to the web root of this installation. If you want to put it on another computer, then that will need to have IIS, relevant version of .Net installed.
It would also help if you can setup your local DNS to resolve the name for your computer within the LAN setup so that you can reache the machine using a name rather than the IP.
This will allow you to test the security issues that are client side. For Server side security issues, you will need to create a server in your LAN that is configured similar to the actual server where you would be hosting your site.
You need to set up the site in IIS Server installed in your Windows machine to run it locally
See the links to learn more:
http://www.beansoftware.com/ASP.NET-Tutorials/Set-Up-IIS-ASP.NET.aspx
http://support.microsoft.com/kb/323972
You need an ASP.NET hosting service.

Weird System.IO error after migrating an asp.net 1.1 application to 4.0

After migrating an ASP.NET application to 4.0, i get a weird System.IO error: System.UnauthorizedAccessException: Access to the path 'xxxx' is denied.
Why is this weird.. the server is also running my 1.1 application, also hosted on IIS7, and working with the exact same folder (outside the application).
NETWORK SERVICE has write access to this folder, and most of all, the 1.1 application just works and doesn't throw the exception.
I'm hosting more 4.0 websites, and never had this problem.
Hope someone can help me out!
give a full read/write and execute permission in that folder...
Does the V4 web application have "AppPool Identity" enabled>
If so you need to ensure the app pool user has appropriate access to the resources (application folder, database, ...) by the app pool identity and not Network Service.
See here for more details on assigning access to app pools. Note, most of the GUI approaches only work on Windows 7/Server 2008 R2 for IIS7.5; with Vista/Server 2008 for IIS 7.0 you'll need to use the command line. With SQL Server you'll need to use SQL statements to create logins/users that map to app pool identities (once created you can use the GUI to assign roles/access.

WCF service works in cassini, but not in IIS

I created a service that has a database connection which is working fine in Cassini, when in copy the service to the inetpub all works fine except database calls, they always return this error:
The server encountered an error processing the request. See server logs for more details."
Now i have 2 questions,
I can find server logs in my C:\inetpub\logs\LogFiles\W3SVC1 folder. But are these the ones mentioned because these do not seem to contain any usefull data.
How is it possible that everything works in Cassini but not in IIS?
If there are any questions about my question please go ahead!
Edit I am using Visual studio team system 2008 and IIS 7.0
This is normally a permissions problem.
If you are using defaults:
The connection string is using a trusted connection
When you run via cassini you are in the security context of your user
When you run via IIS you are in the security context of the identity of the application pool which is network service.
To fix it you could:
change the connection string
change the identity of the application pool
give network service access to your database
Run Visual Studio as administrator
My guess is permissions. Are you using Windows authentication?
In the case of Windows authentication:
http://www.codeguru.com/csharp/.net/net_security/authentication/article.php/c7725

Categories

Resources