I finally want to deploy my asp.net WebApi to IIS 10.
The site works flawless on localhost, but as soon as I try to do anything Database related, I get an Internal Server Error (500).
I checked the connectionstring and it seems to be correct.
I added a user for Domain\MachineName$ on SQL Server.
my connectionstring:
<add name="myDB" connectionString="data source=correctserver;initial catalog=correctdatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
one of the failing requests:
var request = new XMLHttpRequest()
request.open('GET', hostedserverurl + '/v1/correctapicall/' + correctrequestparameter, true)
Error happens here:
request.send()
Expected result: the same as from localhost, JSON if using direct API call.
Actual result:
Errormessage: ("Fehler" is german for "Error")
{"Message":"Fehler"}
I spent quite some time on this and now I'm on the finish line. But it seems it's more a finish wall...
What do I need to configure? I did not setup anything special.
EDIT:
After enabling more extensive error messages with the help of the webconfig, I was able to get to this inner exception:
"ExceptionMessage": "Die SELECT-Berechtigung wurde für das __MigrationHistory-Objekt, correctdatabase-Datenbank, dbo-Schema, verweigert.",
"ExceptionType": "System.Data.SqlClient.SqlException",
This leads me to believe this is a user priviledge related thing... But I already created a user for the IIS.
I get this every time I copy the production database, rename it to be my dev database and forget to add my dev user to the new dev db - the very first thing that EF tries to do (when you carry out any database action) is establish the existence/setup the migrationhistory table - if the user it's using doesn't have the privileges or doesn't exist, an error like this occurs
Ensure that the login/user pair the application pool is running under, exists in the database. If your IIS App Pool is called Wiggle, then you'll need to create a login/user pair for [IIS APPPOOL\Wiggle] inside the DB and ensure that that user has rights to create tables, perform all CRUD operations etc
You can see which app pool your site is using in IIS Manager; select the site, and click basic settings in the top right
ps; if this still isn't working out, you should post up some screenshots of the config pages where you have set up your site, your site's app pool (and the local identity it uses), and your SQL server user. Don't obscure them like I have here, because we need to see them to check what they're set to:
Website settings:
App pool settings:
SQLS settings:
Related
I have created a new SQL Database on Azure, and have copied the connection string directly from the Azure Portal.
On my .NET application, when I am trying to run 'Update-Database' command in Package Manager Console to commit the migration, I receive the following error:
Error Number:18456,State:1,Class:14 Login failed for user
'benhayward'.
Extra Information:
- I have changed my database admin password.
- I have confirmed that the log-in credentials are correct.
- I am on the Azure free trial.
Any advice or assistance on this would be greatly appreciated.
Ok a slightly embarrassing solution, but the reason this wasn't working is because of the curly brackets surrounding the password, as LeonYue suggested.
I had the same issue. The problem was that I had two entirelly different connection strings with the same name in different config files. The right one in app settings was being overwritten by another connection string in my user secrets. As soon as I deleted connection string from my secrets, everything went fine without any errors. Hope my solution will help the others
I'm developing an asp.net mvc application at my office. I wanted to work at home as well, so, I pushed my project on github, when I came my home back, I pulled it from github to my projects folder, now I tried to access its SQL Server database in server explorer using windows authentication, on pressing ok, it showed me the following error :
Cannot open database "HrAndPayrollSystem.Models.HrAndPayroll" requested by the login. The login failed.
Login failed for user 'user'.
and here is my connection string :
<connectionStrings><add name="HrAndPayroll" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=HrAndPayrollSystem.Models.HrAndPayroll;Integrated Security=False" providerName="System.Data.SqlClient" />
What could be the reason, how should I resolve it? Thanks in Advance :)
So, I somehow managed to get through this.
In other words, this error says that you need to access your database at least for a single time, means you need to perform some transactions with the database, inserting something or retrieving something, at this point you accessed the database for the first time on the different machine. Since, I had to access database at the point when my application starts, so, crashing start crashes my whole application, so I created another controller that does not contain any authorize attribute, just to leave it open in order to access the database, created a single field, accessed the database, now go and check your database in server explorer, you are about to access it for the first time in the database, and now also, it will never crash anywhere.
So, the point is that you need to access your database at least for a first time..
I'm using Phil Sturgeons Rest as an API between the server and mobile APP. Locally this works brilliantly, on the server it bounces back with an issue when using API Keys authentication:
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
This is while $config['rest_enable_keys'] = TRUE; is enabled, when I change the variable to false the API service works just fine. Both locally and the server are running the same table layout and both have the same API key in the keys table. Rest of the site works fine doesn't show any database connection errors.
Changing the line $config['rest_database_group'] = 'default'; prompts a different error, which would lead me to believe that it is infact connecting to the correct database, just can't establish the keys table?
You have specified an invalid database connection group.
There's no difference in the code between the server and locally yet locally I get the correct error message of {"status":false,"error":"Invalid API Key."}
Could this be an issue with using multiple database connections? I checked the environment and it seems to be correct but this wouldn't explain why it would work locally.
Thanks a lot to nithin-meppurathu who helped me debug the core of the rest library to find the problem.
The problem lied in the multiple database connections, due to switching what is used depending on the environment it was always being defaulting back to the 'default' database environment. Changing $config['rest_database_group'] = 'default'; to my ENVIRONMENT variable I was able to get it pointing to the correct place.
We have a .NET3.5 Windows Forms application that calls an ASP.NET SOAP web service on the same server. This web service then saves the data into a SQL Server Express 2005 database, again on the same server.
The application has been deployed internally, as well as to a number of our customers and has worked as expected for over 18 months. However this week, at our main customer's site, the application has started generating an error message on four out of the 10 servers it is deployed on. All of the web service methods use the same connection string, but only one web method is affected.
The connection string has this format:
Data Source=MYSERVER\SQLEXPRESS;Initial Catalog=MyDatabase;
Persist Security Info=True;User ID=MyUser;Password=MyPassword
When the application calls one particular web service method, it is producing an error:
Cannot find the user 'MyDatabase', because it does not exist or you
do not have permission.
There have been no changes to the application to cause this, however the customers' IT people may have made changes to these servers. MyUser has been granted permissions on the stored procedures and is able to connect to all of the other web service interfaces.
The main thing that is confusing me is that the error messages says that the user that does not exist is MyDatabase which is the Initial Catalog name in the connection string.
I have been onsite with the customer and verified that the application is still set up correctly and that all of the other web service interfaces are correctly connecting to the database.
Any suggestions of either possible causes or other things I can check would be gratefully received.
I would strongly advise against removing the dbo. That is the schema name. Simply removing it will imply to the DB to use the default schema, which is probably dbo anyways. So it would accomplish nothing. But by not using the schema name when calling the procedure you can run into naming conflicts. For example, if you have a procedure with the same name in two different schemas in the DB, and you try to call it without a schema name, the DB will not know which one to call, resulting in an exception.
I have a silverlight application where when I run the application I read the database and populate the results in the combobox, but when I publish it on the server(IIS) the it returns me a null, I can't even debug the error because it return the result when I host it on my system but null when hosted..
Please guide...
Taking a stab in the dark here. Most likely this is a security issue. When debugging locally, your web server runs under your credentials. If using integrated authentication to your database, then the web service host acts like it is you when making requests to the database. However, when you deploy, the server tries to connect to the database using the credential associated with the application pool that is running your site. Check your database connection string to see if it is pointing to the right database and try using a named user/password with an account that does have access to the database.
If this doesn't fix the problem, try accessing one of your services directly (using Fiddler?) to see what the service is returning as an error message that your Silverlight client is ignoring.