SqlException (0x80131904): Invalid object name 'PlanningRow' - asp.net

I have an asp.NET MVC 3 application which uses nHibernate and SQL Server Standard Edition. The production-environment works fine, and was developed by someone else.
I'm trying to set up a test-environment on my local PC, and restored a backup from the live Db to my local SQL Express. Changed the connection strings, and got the sessionfactory running. (I'm still learning the different aspects of asp.NET MVC, so I'm not totally confident I've checked everything that needs to be checked).
Unfortunately, now when the index.cshtml is loaded, it fails with the mentioned error (SqlException (0x80131904): Invalid object name 'PlanningRow'). It fails on the line:
planningRows = Planner.GetCurrentSession().QueryOver<PlanningRow>().List();
I've seen similar problems posted on StackOverflow and elsewhere, and I know the error means it can't find the table- but the Db and the table are on my local SQL Express. But it is very well possible the database or table is not in the right schema or the schema does not exist. Unfortunately, I don't know what that actually means, let alone how to fix it, and I can't really find hints about how to do this.
(f.i. SqlException (0x80131904): Invalid object name 'dbo.Categories' gives some interesting options- especially option 2- but no way how to check or fix this).
Can anyone point me in the right direction?

double check the connection string points to the correct database
enable SQL-logging with "NHibernate.Sql" in DEBUG mode
check the mapped schema in PlanningRow mapping and default schema in hibernate.cfg file or config code

Related

Problem with ASP.NET MVC application deployment

I'm currently deploying my ASP.NET MVC5 project. I already deployed project files, but I got some problems with, I guess, the database. I did the following steps to deploy the database:
Update-database -script in Visual Studio to get the SQL script of my local database (I developed it by code-first)
Connect to the SQL Server database I created in my hosting panel.
Run the script I generated in 1.
Change the connection string in my web.config to this:
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=xxxxxx.xxxwebix.xx,2401;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxx"
providerName=".NET Framework Data Provider for SQL Server"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
So basically I filled it in with the same credentials I had used to connect to the DB to run the script.
Unfortunately, I'm unable to register or login. I get an error
An error occurred while processing your request.
500 (Internal Server Error)
in the console, which doesn't exactly say what's wrong. So basically, I know that the problem probably concerns the database, but I don't know what's wrong and how to get rid of it. This is my website (maybe it will help somehow):
http://gymmanager.bartoszchodyla.pl.hostingasp.pl/
I'd be thankful for any help.
EDIT
I found the problem - providerName. That's weird because I took it from the database properties after I connected to it in Visual Studio. I changed it to default "System.Data.SqlClient" and it worked. Does someone knows why?
There are a lot of things that could be going on here. The fact it is throwing a 500 error means either some code is causing a major error and/or you do not have friendly errors turned on.
There are some things you can do to figure out exactly where the issue is. In your console, make sure friendly errors are turned on, and you should get a bit more information. You can also add try ... catches to where you think the issue is and avoid the exception and write a message instead (this is fairly crude, but quick and easy). Turning on tracing can also work, as long as you can actually spin up the application without the 500. You add trace statements before and after each routine and then go an examine the trace file. The same can be done, in more crude fashion, by writing to a file. The use of this method is you can turn trace on and off at will.
The fact you used code first is non-important if you are creating a SQL Script the correct way. When you run it, as long as it works (creates and possibly seeds?), you have the correct schema.
So, does the app throw the error up front or only when accessing data? If the latter, you have a good place to start seeking out errors.
BTW, you may be able to test locally against your providers database by changing your local connection strings. It will depend on having certain ports open, which you might even be able to do if they are not for security reasons. You can then debug the exception locally.

System.Runtime.InteropServices.COMException (0x8004100F)

so Hi everyone, struggling to solve this almost for a day, i haven't used crystal reports much, so please point me in the right direction.
Here is the problem, we have an asp.net web site using crystal reports. All the reports seems to work fine except one. The Report is opening when it is running in local, but when deployed to the server it is throwing "System.Runtime.InteropServices.COMException (0x8004100F)" error.
when i searched for it, it is a logon error, if thats the case it shouldnt work from local either, and other reports using the same connection also working well when deployed in server.
Taken from SAP:
If it's only certain reports, the compare the reports:
Connection type (OLE DB, ODBC, etc.).
Is it reports with subreports only? If so, check the above and log on to the subreports.
Check other differences. parameters? Tables vs. Stored Proc, etc., etc.
You may also want to troubleshoot by trying out the 32 bit runtime
Okay, currently the report is working, maybe of help to someone else facing the same problem.
In the report database properties, the Locale Identifier of the connection was set to 17417 which is English-Malaysia(dont know why and how), i changed the connection Locale Identifier to 1033 English-United States and now it is working in the server.
Database -> Set Datasource Location -> report -> properties -> Locale Identifer
If someone could reply how the locale identifier got set to 17417, it would be a great help.
Roy, I believe you set local identifier when you create database connection.
enter image description here

Database permission denial when using IIS

Not entirely sure how to phrase this, so I'll just give as much information as possible.
I've got an asp.net application that uses SELECT on a database table. The connection string is something to the tune of:
"Data Source=Data\Source;Initial Catalog=DataStore; Integrated Security=True"
This works when I use the application locally. Query is executed, information is retrieved, everything's gravy.
The problem is when I try to publish my website using iis. After I publish it, I get the following error when I try to execute the query:
The SELECT permission was denied on the object 'object', database 'DataStore', schema 'dbo'.
I'm kind of stumped here and I'm not that familiar with IIS or security. Any help is appreciated, and I'll try to answer any questions you might have as quickly as possible.
You have the classic double-hop problem, you can read about it many places, like here and read how to do it right here, or go the easy route and put sql authentication user name and passwords in clear text in your config file.

ASP.NET MVC4 Code First - 'Cannot attach the file as database' exception

I'm using Code First concept in Entity Framework and I'm constantly getting the following exception while starting application:
Cannot attach the file 'C:\Users\Admin\Documents\Visual Studio 2012\
Projects\Pro\Pro.Web\App_Data\Pro.mdf' as database 'Pro'.
I've put this in Global.asax.cs but also without success:
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<ProWebContext>());
var ctx = new ProWebContext();
ctx.Database.Initialize(true);
I've checked under App_Data directory and there no database created. Also, under Server Explorer there is nothing under Data Connections. Everything was working fine yesterday and today not working at all. I've tried to connect to LocalDB with SQL Server Management studio but it says it cannot connect to local database. Any ideas what could be a problem?
Thanks!
I found the solution. With newest SQL Server Management studio there is no problem in connecting to the local database. Connection needs to be established like this:
After logging in we can still see old database present even if there is nothing under App_Data directory and under Data Connections in Server Explorer in Visual Studio. When we delete that database from SQL Server Management studio and start application again there will be no more errors while attaching database.
I was facing the same error when I saw this but I couldn't delete the database using SQL Server Management Studio so I remembered IDatabaseInitializer.
Setting a database initializer for my Code First context solved the issue. In my case adding an initializer to always drop the DB worked (I added the code in the static constructor of my context, most people add it in Global.asax):
static SomeDbContext()
{
System.Data.Entity.Database.SetInitializer(new DropCreateDatabaseAlways<SomeDbContext>());
}
There are other initializers of course.
I just got into the same problem, and yet the answers above helped, the solution was different.
In my case, I was reusing a project that has already created it´s database. And since the name in the config was the same, it was throwing the exception, missleading the real solution.
It worth checking the database is not created and is different than the ones you used before. Change the name and go ahead.
I deleted the mdf file manually so the code will recreate it again, and had the same problem. I solved it by running update-database command in the package manager console.

Creating Membership DB (ASPNETDB) on remote server?

I'm building a web application which soon I'll be promoting to production. This application has a login screen, as you know I used the integrated DB for developing. Now I want to move this database to a full SQL Server 2005. I'm using the aspnet_regsql.exe to create my membership tables and stored procedures in the SQL Server 2005 but I'm getting an error:
An error occurred during the execution of the SQL file 'InstallMembership.sql'. The SQL error number is 207 and the SqlException message is: Invalid column name 'FailedPasswordAnswerAttemptWindowStart'.
I google this for half of the day already and I can't seem to fine what's wrong, does anybody have ANY ideas on what am I doing wrong here? Any help will be really appreciate it.
The easiest way to deploy a brand new database to a remote server is to just publish the database from within Visual Studio. Once you do that you have the scheme and data all in one script. You then access your server either via a local SQL manager connection or a remote manager and run the script on your remote database.
The site 4GuysFromRolla has a nice little walk through with graphics which describe how to accomplish the publishing of your local database to your hosted one.
Good luck, and hope this helps you out some.
Go through the *.sql script file and see where that column reference is. Then you'll be able to see what exactly the script is doing to cause this error. My guess would be that it is getting caught up on referential integrity. If it is trying to create a foreign key constraint that that table/column does not exist then you'll see that error.
But back to the original question at hand. You don't need to recreate your whole database. That script file is to lay down the Membership for an empty database. If you have a working dev database you can just back it up and restore it to a production instance. No need to rebuild the membership database objects.

Resources