SQL Server Express error: Operation is not valid due to the current state of the object - sql

We have a problem with our SQL Express server and need help please. We use this SQL Express server with a banking program on one windows computer. When we try to do some task in the application which was always working fine before we are now getting a error:
Operation is not valid due to the current state of the object
Google is showing me that we should add entries in web.config file to fix this problem. It is explained here:
http://sqlservercentral.com/forums/topic/sql-server-reporting-services-error-operation-is-not-valid-due-to-the-current-state-of-the-object
http://social.msdn.microsoft.com/Forums/sqlserver/ar-SA/c9d4431a-0d71-4782-8f38-4fb4d5b7a829/ssrs-operation-is-not-valid-due-to-the-current-state-of-the-object?forum=sqlreportingservices
The problem is that it seems the web.config file does not exist in SQL Server Express and I'm not able to fix this issue.
Where can we apply this settings on a SQL Express Server? Does a express server have this web.config file?

Related

Updating connection string in IIS10 and SQL Server 2019 Express

I have a working web site that is running in IIS on Windows Server 2008 R2 and using SQL Server 2008 Express. I am trying to port the entire site to Windows Server 2022 using SQL Server 2019 Express.
I moved all the code, set up all the permissions like the original set up, but I just can not get the database connection to work. I am using the same connection string, so this is leading me to a permissions issues on the database. But with the use of localDB, I am not sure if there is an issue there.
I previously used the IIS APPPOOL\APP PoolName to access the database, so I was hoping this would continue to work. This does not appear to be the case at the moment.
The error I am getting though looks like the old way will not work:
Parser Error Message: The sqlConnectionString attribute or the connection string it refers to cannot contain the connection options 'Database', 'Initial Catalog' or 'AttachDbFileName'. In order to allow this, allowCustomSqlDatabase attribute must be set to true and the application needs to be granted unrestricted SqlClientPermission. Please check with your administrator if the application does not have this permission.
The connection string currently in use is:
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db_name_chgd.mdf;Integrated Security=True;MultipleActiveResultSets=True
I have not been able to find any new info on connecting to a SQL Server Express local database on the same web server. I am NOT using the localDB, but if I need to change to that sort of a config, I would like to read up on the required changes.
So the solution that worked for me is the following.
In the web.config file I commented out the SessionState tag....
<!-- <sessionState allowCustomSqlDatabase="true" mode="SQLServer" sqlConnectionString="ConnectionStringMyConection" sqlCommandTimeout="30" cookieless="UseUri" timeout="20">
</sessionState> -->
Everything worked fine after that.

Unable to Publish SQL Server 2014 database using Web Deploy in VS 2013

Its been quite sometime that I am trying to publish the data base for my website using webdeploy in VS 2013 but I keep getting the following error:
Web deployment task failed. (Could not generate deployment script.
Internal Error. The database platform service with type Microsoft.Data.Tools.Schema.Sql.Sql120DatabaseSchemaProvider is not valid. You must make sure the service is loaded, or you must provide the full type name of a valid database platform service.
I have tried installing the new updates. I am making sure that the local server is running during deployment. I have made sure that I enter the full server name rather than a dot. I have literally done everything that I could think of but to no avail.
Can anyone help me, please?
The issue might be related to VisualStudioVersion environment variable, which needs to be set to VisualStudioVersion=11.0 or VisualStudioVersion=12.0 to support SQL Server 2014. Check this answer, also here is the info how to target the VisualStudioVersion.

Package Microsoft SQL Management Studio Package’ failed to load

Sql Managment Studio stop working, sending me this message:
Package ‘Microsoft SQL Management Studio Package’ failed to load
I follow the solution from this page
http://blog.dotsmart.net/2012/01/04/solution-for-package-microsoft-sql-management-studio-package-failed-to-load/
I delete it HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100 key, just like the page says. Now, ssms.exe it's not starting!!! Not even an error message. The article says that, after restart the machine, the registry will be recreated, but I don't have the registry! What am I missing? Now I don't have error message nor Sql Managment Studio!
I don't know how to help you get back the sql server but for those that haven't deleted "HKEY_CURRENT_USER\Software\Microsoft\Microsoft Sql Server\100\Tools" yet, just rename it to "HKEY_CURRENT_USER\Software\Microsoft\Microsoft Sql Server". You don't have to delete the whole thing. That should work but it doesn't fix it for some. If that is the case, check your .net permission setting s. You might have changed MY_COMPUTER_ZONE code group from full trust to everything. Change it back to full trust. Note that .net permission settings cannot be changed in version 4 and later versions.

Page does not load after I migrated the database from SQL CE to SQL Server

I am running into an issue. I have developed a site in webmatrix with SQL server compact edition. My site is ready and I can see it run without any issue in my PC. However, I ran into an issue after migrating the database to SQL server. Migration finished successfully and I can see all my tables, data in the migrated database. But I can not run the page anymore. In IE browser, it gives me error Page cannot be displayed. (In other browsers it just tries to load indefinitely).
I don't know what is the issue. If I remove the migrated database file(.mdf) and put the .sdf back in APP_DATA folder and connect it in database workspace, my site starts working again.
Note: I can see a connection string added to web.config file when migration is completed.
Verify that you can connect to the migrated database from within SQL Server Management Studio(SSMS). Your connection string in the web.config file needs to be correct and should look something like:
<connectionStrings>
<add connectionString="Server=SERVER01;Database=mydatabase;Uid=user;Pwd=password" name="somename" providerName="System.Data.SqlClient" />
</connectionStrings>
After logging in through SSMS you will know what the settings should be. I hope this helps you.
Thomas, thanks for your reply. Glad to let you know that issue has been resolved. The issue was regarding the sql server version. Basically I had SQL commands like "fetch first n rows only" etc. Now, this is not supported in SQL 2008. My migrated database was in 2008. When I imported the data into SQL 2012 database, it started working now.

How can i test my TSQL syntax?

Quick question: How do I get some kind of database to use to test my SQL syntax and create basic data.
I have Sqlite Code which I'll soon put on a server. I have SQL Server 2008 installed with visual studio 2010. I tried connecting to the database and had no luck.
I also tried using an .mdf file instead thinking it's a file and I won't have connectivity issues. Wrong, I still couldn't connect and I used this site to help me (i'm aware its 2005)
In that case I used:
var conn = new SqlConnection(#"Server=.\SQLExpress;AttachDbFilename=C:\dev\src\test\SQL_DB_VS_Test\test.mdf;Database=dbo;Trusted_Connection=Yes;");
exception
Unable to open the physical file "C:\dev\src\test\SQL_DB_VS_Test\test.mdf".
Operating system error 5: "5(Access is denied.)".
Cannot attach the file 'C:\dev\src\test\SQL_DB_VS_Test\test.mdf' as database 'dbo'.
With trusted = no I get Login failed for user ''. (What user am I suppose to set?). I created the .mdf with Visual Studio somehow.
What if you try this connection string:
var conn = new SqlConnection(#"Server=.\SQLExpress;
AttachDbFilename=C:\dev\src\test\SQL_DB_VS_Test\test.mdf;
Database=test;Integrated Security=SSPI;");
I don't think it's a good idea to call your database "dbo" (that's a SQL Server keyword - I wouldn't use it for my own purposes!), and also I believe you need to use Integrated Security=SSPI; to define Windows authentication - Trusted_Connection is not used for SQL Server connection strings, AFAIK.
Have you tried using SSMS to access your local instance? It's helpful for getting connected and getting everything setup. Also, I think the default install of Sql Express with VS only support trusted connections.
After creating the mdf file with visual studios right click the mdf and select properties. In it you'll see a row called Connection String. Copy/paste it into your app and it should connect. The key part is User Instance=True