MVC4 published application account logon page does not load - c#

I have created an MVC 4 application using the standard Internet Application template.
I have added some other controllers, views, model and a connection to my own sql database which is working correctly.
When i publish this to a file location to access via my IIS8 on my windows 2012 server the application works except for when i click on logon or register links.
I have not made any changes to the registration or logon parts of the application and as such the Account controller and model have remained the same as has the DefaultConnection string in the webconfig file see below
enter <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-mvcdev-20131010105728;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-mvcdev-20131010105728.mdf" providerName="System.Data.SqlClient" />
I have a couple of registered members and have some views and controllers that require an authorised user to run correctly.
The error i get when i try to access the Account/Logon or Account/Register is:-
Server Error in '/' Application.
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 50 - Local Database Runtime error occurred.
Cannot create an automatic instance. See the Windows Application event
log for error details. )
The 2 event logs are
Unexpected error occurred while trying to access the LocalDB instance registry configuration. See the Windows Application event log for error details.
and
Cannot get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS, make sure that profile loading is enabled for the current user.
Has anyone else come across this or have any links to some helpful resolutions?
The application was published to a folder in the Public Documents of my windows server and is being accessed currently of machines on the same LAN

I was also suffering from same problem but there is so small solution for it
just go in iis server than to application pool from which you application is running and in advance setting of application pool we will get the option of Process Model under which there is identity which is by default application pool identity just change it to Local System and your done
And Remember to Put App_Data Folder their in WWW folder of IIS server

If you used the Internet Template for MVC 4 it uses SimpleMembership as the membership provider and automatically wires it up. If you did not make any changes to the basic configuration SimpleMembership is configured in the web.config to use a local database (localDB). SimpleMembership uses EF code-first with lazy initialization. So it checks if the database is available the first time you try to access any of its methods, such logon and registration. If the database is not available it tries to create it. These error messages probably indicate that it could not create this database. If I had to guess you do not have the proper privileges on the server you are deploying to to create a localDB. It is trying to create it in the App_Data folder. Check to make sure that the application has privileges to create files in this folder. The better solution for a production application is to use SQL Server and just change your connections string to point to it instead.

Related

ASP.NET Core Web 3.1 - IIS Express can fetch data from localdb but local IIS can not

I have a very weird problem as stated above.
The code running is exactly the same, the only difference is the Debug profile used. I'm using Microsoft Visual Studio Community 2019 Version 16.6.3.
When using the IIS profile the code says I have no Media in my database.
Switching profile to IIS Express, now I have Media using the exakt same connection string as can be seen in Immediate Windows.
I first suspected that the ASP.NET Core Web 3.1 had a problem fetching the connection string from appsettings.json and that it was needed in web.config as well. Tried adding it but it did not make a difference. Checking context.Database.GetDbConnection().ConnectionString also shows the same for both profiles so this is not the case.
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=(localdb)\\mssqllocaldb;Database=<MYDB>;Trusted_Connection=True;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
</connectionStrings>
If I look at the database via SSMS I can see my Media as expected.
The IIS Application Pool runs as LocalSystem. If I switch to a user that does not have access to the database like ApplicationPoolIdentity I get an exception as expected in Windows Event Viewer and the application does not start correctly.
Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related
or instance-specific error occurred while establishing a connection to
SQL Server. The server was not found or was not accessible. Verify
that the instance name is correct and that SQL Server is configured to
allow remote connections. (provider: SQL Network Interfaces, error: 50
Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
Using LocalSystem everything looks fine in Event Viewer but it says I have no Media or any other data.
How can two identical connection strings using the same code show different results?
Tried switching Application Pool Identity to my currently logged in user that I know has access via SSMS:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 50 - Local Database Runtime error occurred.
Error occurred during LocalDB instance startup: SQL Server process
failed to start. )
With this and the comment from #nilsK I fixed it like this:
Start by using Developer PowerShell or Developer Command Prompt for Visual Studio as Administrator and confirm that you only have one instance of LocalDb.
Type sqllocaldb info to see your LocalDb instances.
I then followed this article and had Application Pool Identity still set to my currently logged in user, credit: https://stackoverflow.com/a/38294458/3850405
https://learn.microsoft.com/en-us/archive/blogs/sqlexpress/using-localdb-with-full-iis-part-1-user-profile
In there I found that it is not enough to have Load User Profile set to true for your Application Pool, you also need to set setProfileEnvironment to true in applicationHost.config normally located at C:\Windows\System32\inetsrv\config. With this configuration it worked:

Network naming: no LDAP server detected or configured

I am trying connect existing oracle database of existing project using asp.net. I have direct access to the oracle database.But for now I have created a simple table in the existing live oracle server and I am trying to connect to that server by creating a simple registration page in asp.net.
I am totally new into oracle and its configuration. I need to know the steps to connect my current asp.net application (login page and registration page). I am not using anything else other than visual studio 10 and oracle server (same error after trying to connect on local oracle server 11g)
The error message/exception i am getting is "Network naming: No LDAP server detected or configured"
What I have tried?
I have changed the connection string in the back end i.e the xyz.aspx.cs file, i have not made any changed in the web.config file.
I resolved this error by copying my ldap.ora (and other config files) over to where tns.ora file sits by default as described here:
if I select tns as connection type in Add Connection dialog box that's
when I come to know about tns file's default location.
I had the same problem with vs.net 2019.
Error when creating db. conn. in IDE: Network naming: no LDAP server detected or configured. I resolved it by removing LDAP from sqlnet.ora file, from NAMES.DIRECTORY_PATH param.

Access ASP.NET with database running on localhost through LAN

I am using Microsoft Visual Studio 2013 Ultimate.
I have one C# application connected with WSN to collect and save all sensor readings in database. It is working fine and stable.
Later I decided to add ASP.NET application (developed in the same software) so other computers in LAN can access my page and check measurements. I have one web form with few labels and buttons to ensure move forward and backward through the database table. It is working fine when I start it from Visual Studio but when I am trying to access from IIS it does not work.
I have this error (main part of the text):
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
I have installed IIS and I can access "localhost" from my browser (IIS image appears). I published site with "Publish" option from Visual Studio.
I saw a few very similar questions on this forum but I did not find answer. Can you recognize what can be the problem?
Regards.
I think DeanOC's answer will apply if you are using your windows login to connect to sql server (in connection string you'll have Integrated Security=true) in which case:
In IIS select you web application on the righ side click Advanced Settings a dialogue box will pop up in it you can see which application pool your website is using
Close dialog go to Application Pools, right click the application pool you want and go advanced settings
Change the Identity of the application pool, under Process Model, to your current windows login.
http://www.codeproject.com/Articles/674930/Configuring-IIS-ASP-NET-and-SQL-Server
Everything is well explained. Just follow the procedure and it will be - Yeah, solved. :)
The message implies that either sql server instance you are pointing to is not running or that you are pointing to the wrong sql server instance. If you are able to run the application from visual studio then sql server should be running and that would imply that your connection string is wrong.
During publish, msbuild will run config transforms i.e. if build profile is set to release it will change the connection strings in web.config to those in web.release.config. Check your connection strings in the IIS website and also check you password is correct
You could enable TCP/IP in SQL Server Configuration.
Microsoft SQL Server xxx -> Configuration Tools -> SQL Server Configuration Manager -> Select TCP/IP. Right click and select enable
Therefore, you can connect successfully from your local computer but it fails when you access from IIS of other server.
I think you are trying to access the web page from another computer in the network and not sql server in which case you have to add a binding to your site. By default the site is only bound to localhost port 80 meaning it will only be accessible from within the same machine. You'll need a url with dns entries or a static ip address to use to connect to your machine. Check out IIS bindings:
http://blogs.technet.com/b/chrad/archive/2010/01/24/understanding-iis-bindings-websites-virtual-directories-and-lastly-application-pools.aspx
http://technet.microsoft.com/en-us/library/cc731692(v=ws.10).aspx
because you used attach Mode in this way when one of them is connected to your database other one cannot use it like open file. and only the one who is in the same sever could access to your database.
to solve this problem you have to add your database to your SOL server manager after that you could access to it from many devices use
this connection string
Data Source='server IP';Initial Catalog='database name';Persist Security Info=True;User ID='your user name';password='your password'
please follow this video
enter link description here

Remotely accessed database can be accessed on localhost but not from the server

I have deployed my web application (ASP.NET MVC 3 C#) locally on my own computer and then uploaded the files by FTP tools on Godaddy.com hosting server.
The website works like a charm except the database connection.
I have deployed the database by generating scripts of my tables and created a database in godaddy database server (SQL Server) and simply just executed the scripts to create tables with data inside it on the server database.
I have configured the web.config connection string according to the provider's guides on the connectionString.
The problem:
I have used the same web.config on both my local computer and also the files on the host server with the same connectionString and everything.
When I run my not-deployed-version of my web application on my own local computer on localhost.. It can access the database perfectly without any issue in fetching the data.
But when I open my Live website on internet, it gives me the "Resource not found" error.
I have mentioned the problem with customer service, they were checking everything in my hosting account for hours they did not find anything unusual or wrong with it. But the problem still exists.
So technically, I am using the SAME web.config trying to connect to the SAME database but it works locally, but not on the server.
Is there anything in ASP.NET MVC modeling that I have been missing or not aware of?
This issue is driving nuts. Any help would be deeply appreciated.
EDIT:
<connectionStrings>
<add name="CarContext" connectionString="Data Source=moamzia.db.10412552.hostedresource.com; Initial Catalog=myID; User ID=myId; Password='Mypassword';" providerName="System.Data.SqlClient" />
</connectionStrings>
I also just realized that my links are not working on the internet. Could it be the way I uploaded my files were wrong or something? Because my controller and Model are both missing in the deployed version of the application.
Then how does the localhost ever find the controller when it's not in its files?
UPDATE:
Thank you all for your comments.
After a little more of research and investigation, I found out that the problem is something about IIS or compiler on the server or the file directories or something.
The reason I say this is that the website on the internet does not compile ANY C# codes at all. It just compiles the plain HTML and CSS files.
Also after few hours, now I get this error when I open the website on internet:
Server Error in '/' Application.
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
However, unfortunately, I am not much familiar with IIS or its role in website deployment. Any information regarding this would be really helpful I suppose.
Thank you.

How to access the database Remotely through IIS?

I have used the ASP.net with C#. I want to access the SQL Server database through web server. When executing my application from development area it's working but after deploy the application to the IIS server it shows the following exception:
CREATE DATABASE permission denied in database 'master'. An attempt to
attach an auto-named database for file D:\newtest\newtest.mdf failed.
A database with the same name exists, or specified file cannot be
opened, or it is located on UNC share.
I have used the following connection string to attached with database
Data Source = .\\SQLEXPRESS;AttachDbFileName=databasepath; Integrated Security=true
How do I access the SQL Server database Remotely through IIS?
Although the answer by Sanjay is correct, it doesn't really explain why you're getting the permission denied.
Code running in ASP.NET / IIS runs as a specific user, as defied in the worker process' config. For IIS 6 [Server 2003] (and below, I think) the default was NETWORK SERVICE for IIS 7+ [Server 2008], the default behavior is to run as a special application pool user IISAPPPOOL\yourAppPoolName.
If you grant the requisite permissions on your database for the correct user account(s) -- you should be able to get around the error and still use integrated security.
As an aside, it is generally a good idea to give the most restrictive (yet still operable) set of permissions on your database. CREATE DATABASE requires a pretty high permission level (I don't remember what off the top of my head.) If you grant that to your IIS application, you run a significant risk of allowing a less than honorable user taking control of your database system and wreaking havoc on it.
Hey Create Credential with SQL server and update your config file
connectionString="Data Source=Abcl\SQLEXPRESS;Initial Catalog=master;User ID=sa;Password=pwd12" providerName="System.Data.SqlClient"
if your are using db file like mdf
Pls use like this
connectionString="AttachDbFilename='C:\Documents and Settings\nmartin\My Documents\PS_Upload\TimeTrack\src\TimeTracker\TimeTrack\App_Data\ASPNETDB.MDF';Integrated Security=True; User Instance=True"
They key is that you've used Integrated Security=True in your conneciton string.
When you run your project in your development environment, the web application usually runs as your local user account. Furthermore, your account is usually a privileged user (admin) on the local SQL instance.
On your deployment server, IIS usually runs as a local machine account (or an account provisioned for your AppPool). That account usually doesn't have any special privileges on the SQL server instace.
As debracey points out, you normally don't want to have your app's SQL privileges high enough to cause any harm (even if it's an honest mistake on your part). One common pattern to avoid tihs is to have two separate SQL accounts for your app:
A high-priviledged account for creating and modifying your database schmea (e.g. db_owner role)
A limited-privilege account for accessing your database while your app runs (e.g. db_datareader and/or db_datawriter role)

Categories