Troubleshooting the Re Creation of ReportServerTempDB - sql-server

RESOLVED SEE EDITS:
Like a total noob I deleted our ReportServerTempDB by accident (I have a backup of ReportServer but not ReportServerTemp, live and learn). (Using SQL Server 2008 R2)
To recreate the database I followed several online guides that gave the several steps:
created a new database with the name ReportServerTempDB, and with the same collation as ReportServer (collation was key)
made a new Database Role called RSExecRole with same users as my ReportServer (also key to make sure this role has the correct permissions to the tables)
ran the CatalogTempDB script which ran without a hitch (the version of CatalogTempDB was not sufficient to recreate all of the objects necessary)
Used Reporting Services Config Manager to Change Database and picked ReportServer
Just for good measure turned off and on the SQL Server Reporting Services a few times
But I am still getting an error when I try to load my Reporting Services Home page:
An error occurred within the report server database. This may be due to a connection failure, timeout or low disk condition within the database. (rsReportServerDatabaseError) For more information about this error navigate to the report server on the local server machine, or enable remote errors
What am I forgetting? As an alternative can I simply "create a new report server database" and import a back-up of my original ReportServer? TIA
EDIT: I reviewed the RSExecRole and made sure that it had permission to edit tables and execute stored procedures (online sources did not spell this out very clearly) and after restarting the Reporting Services my error has changed to "An error occurred within the report server database. This may be due to a... Invalid object name 'ReportServerTempDB.dbo.TempCatalog'. Could not use view or function 'ExtendedCatalog' because of binding errors. "
Further reading is suggesting that the name of the temp Report Server is hardcoded into many stored procedures in ReportServer, but my new temp report server has the same name: ReportServerTempDB. Where is the disconnect?
EDIT2: So the script I used, CatalogTempDB, did not create all of the tables necessary to rebuild my temporary Report Server db. I created a new Report Server and ReportServerTempDB (which an altered name) and compared the object in my ReportServerTempDB built using CatalogTempDB to the one the SQL wizard created. Then used the import wizard to add in the missing tables and re-started the Report Service with my original. Voila.
Happy to provide more details about any of these steps.

To recreate the database I followed several online guides that gave the several steps:
created a new database with the name ReportServerTempDB, and with the same collation as ReportServer (collation was key and you need to assign it when yout are creating the db)
made a new Database Role called RSExecRole with same users as my ReportServer (also key to make sure this role has the correct permissions to the tables and stored procedures)
ran the CatalogTempDB script which ran without a hitch (the version of CatalogTempDB was not sufficient to recreate all of the objects necessary, several tables were missing)
To replace the missing tables I created a second ReportServer instance (using Reporting Services Configuration Manager)and compared the temporary db to my re-built temporary db and filled in the holes
Moral of the story: Keep a back up of BOTH ReportServer and ReportServerTempDB

Related

Can't export SQL Azure database when stored procedure is encrypted

I want to export my SQL Azure database to a file test.bacpac, but I failed:
One or more unsupported elements were found in the schema used as part of a data package.
Error SQL71564: Error validating element [dbo].[IsMyUserExisted]: The element [dbo].[IsMyUserExisted] cannot be deployed as the script body is encrypted.
The question is, why can't I back up my database like in SQL Server 2008, 2017 etc (just backup database, and then restore database).
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\150\SqlPackage.exe" /a:Export /ssn:"servername" /sdn:"databasename" /su:"username" /sp:"passwordhere" /tf:"myfile.bacpac" ExcludeObjectsTypes=StoredProcedures
but the property ExcludeObjectsTypes=StoredProcedures is invalid
I also tried "/p:ExcludeObjectsTypes=StoredProcedures" but still get an error.
Azure SQL Database does not support the WITH ENCRYPTION option for migrating objects such as stored procedures, user defined functions, triggers, or views. Therefore, migrating objects compiled with that option is not possible. You will need to remove the WITH ENCRYPTION option.
It means that Azure SQL doesn't support export/migrate database which contains these encrypted object, we will always get the error like this:
You must unencrypt this procedure then backup the database. After the database restored, find this stored procedure and encrypt it again.
Please ref this blog: https://thomaslarock.com/2013/05/migrate-encrypted-procedures-azure-sql-database/
HTH.

SQL Server - copy table data from one server to a table in an Azure SQL Database

I'm migrating a database from Azure VM to Azure SQL Database. I tried to use the "Deploy Database to Azure SQL Database" function in SSMS but it failed several times, seemingly due to the size of the database (110 GB). So I made a copy of the source database on the same source server, truncated the table with the majority of the data in it, then tried the deploy again. Success.
Now I need to get that data from the original source table into the destination table. I've tried two different approaches to this and both gave errors
In SSMS, I connected to both SQL Servers. I ran the below while attached to the destination database:
INSERT INTO dbo.DestinationTable
SELECT *
FROM [SourceServer].[SourceDatabase].dbo.SourceTable
With that I was given the error:
Reference to database and/or server name in
'SourceServer.SourceDatabase.dbo.SourceTable' is not supported in this
version of SQL Server.
In SSMS, used the Export Data Wizard from the Source Table. When trying to start that job, I received this error during the validation phase:
Error 0xc0202049: Data Flow Task 1: Failure inserting into the
read-only column "CaptureId"
How can I accomplish what should be this seemingly simple task?
instead of using deploy database to azure directly for large databases ,you could try below steps
1.Extract bacpac on local machine
2.Copy bacpac to blob
3.Now while creating database, you could use the bacpac in blob as source
This approach worked for us and is very fast,you may also have to ensure,that blob is in same region as SQLAzure
I've solved the issue. Using option #2, you simply need to tick the checkbox for "Enable Identity Insertion" and it works with no errors. This checkbox is inside the Edit Mappings sub-menu of the Export Data Wizard.

Can I use backup/restore to move a database created with EF Code First?

I have an application that uses EF Code First against a SQL Server 2012 database. I'm using the DropCreateDatabaseIfModelChanges initializer.
I have a database on my development machine that I want to move over to my testing machine, and to do that I'm attempting to use backup/restore. Unfortunately, having done that, I get the dreaded "Model compatibility cannot be checked because the database does not contain model metadata" error.
I don't understand why this is the case - the database works OK on my dev machine. Is it not possible to transfer the database to another machine?
Solved: the issue was that the __MigrationHistory table, while present, was not accessible to the application because of insufficient database privileges. I (temporarily) made the user a DBO on the database, and it all worked fine. (Hat tip to Jayantha).
Now the metadata table is removed from the code first DB and added the __MigrationHistory table to system tables. You can try running Enable-Migrations command in Package Manager Console. Here is more details .

SQL Server Copy Database Issue

I'm running the copy database wizard on a 2008 R2 instance of SQL Server.
The database I want to copy is a SQL 2000 database.
I'm copy that database to another SQL SErver 2008 R2.
The wizard uses SQL authentication for both servers, and both are sysadmins.
When I run it, I get the following error (FYI I have tried both copying the logins and leaving them out):
Event Name: OnError
Message: ERROR : errorCode=-1073548784 description=Executing the query "sys.sp_addrolemember #rolename = N'RandomRoleName..." failed with the following error: "The role 'RandomRoleName' does not exist in the current database.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
helpFile= helpContext=0 idofInterfaceWithError={C81DFC5A-3B22-4DA3-BD3B-10BF861A7F9C}
StackTrace: at Microsoft.SqlServer.Management.Dts.DtsTransferProvider.ExecuteTransfer()
at Microsoft.SqlServer.Management.Smo.Transfer.TransferData()
at Microsoft.SqlServer.Dts.Tasks.TransferObjectsTask.TransferObjectsTask.TransferDatabasesUsingSMOTransfer()
Any help would be appreciated!
Jim
My suggestion is dont use the copy database wizard. Create a full backup of the database on the 2000 server and then restore it on the 2008 server.
If you google "Microsoft.SqlServer.Management.Dts.DtsTransferProvider.ExecuteTransfer Copy Database Wizard" you will find that many many people have gotten this same error or other nearly identical smo errors... no-one appears to have gotten past it.
That's isn't to say its impossible... just, restoring a backup is so much easier then the wizard or troubleshooting the wizard. Good luck.
The copy wizard had missed some security and IIRC it's caused by subtle differences in security tables, principals etc between the 2 versions.
Frankly, the easiest way is to do one of these two:
backup/restore
detach, copy, attach
If you don't have access to the O/S and can't get it, another option is to create the missing role(s) in the background as the copy runs. You have to catch it between the creation of the files and when it tries to reference the roles, but there are a few seconds in which to create them if you keep clicking execute - I managed to create 9 roles.
Unfortunately, you'll end up with the roles in another database too (while yours cannot be used) so those need to be deleted.
Of course, this is only an option when you really can't use the other method.
Though the answer which is using the backup technique solves the problem generally, after facing the same issue several times, I was able to trace down the root of the problem using the Event Viewer of Windows to that the Database Copy wizard, using the SQL Agent, will eventually create a Job for the agent to run, after which the Agent will run using its own credentials (i.e. the credentials that you can look up in Windows Services, in my case, NT Service\SQLAgent$SQL2014)
All you need to do is to go the folder where SQL Server creates DB files (e.g. C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\DATA by default for SQL 2014) and give the SQL Agent windows user write/read access on the folder.
The reason can be that a file with the new Database name already exist on the filesystem. We encountered this when we renamed Database X to X_Old, and tried to copy database Y to X. This cannot be done, because database X_Old is still associated with the filename X.
Either delete the conflicting database, or rename the file on the file system.
See http://codecopy.wordpress.com/2012/01/03/error-while-copying-a-database/

Tables won't show in SQL server 2008 object explorer

When trying to expand the tables on a database in the object explorer I get the following error:
“A severe error occurred on the current command. The results, if any, should be discarded.
”
The database was recently restored from a SQL server 2000 box. I can see two tables that are in the sysobjects catalogue but I can not drop or select them as it says the object does not exist.
Have you tried running DBCC CHECKDB?
What seemed to fix the issue was that the rogue tables had an owner that was a SQL server login account which was recreated but no schema was recreated. I recreated the schema which then let me browse the tables in the object explorer. From there I was able to delete the tables.

Resources