Copying SQL Server DB using script - sql-server

I have to copy a db from a remote server to my local dev machine.
What is the best way to do it.
Last night I made a script for the remote db using xSQL Object and ran it on the local server. the script gave a bunch of errors. Below is the select ##version output for the 2 servers. is there a reason the script is not working
The remote server is using SQL server authentication, the local one is using windows authentication
Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (X64)
Jul 9 2008 14:17:44
Copyright (c) 1988-2008 Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 5.2 <X64> (Build 3790: Service Pack 2)
Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
Jul 9 2008 14:43:34
Copyright (c) 1988-2008 Microsoft Corporation
Express Edition with Advanced Services on Windows NT 5.1 <X86> (Build 2600: Service Pack 2)

It would be helpful if your provided some of the errors your script produced.
I notice you're using Enterprise and Express editions - these two editions have differing features, described here: http://www.microsoft.com/sqlserver/2008/en/us/editions.aspx. Perhaps you're using a feature that Express edition doesn't support, or your database is too big.

Not sure if the functionality is exactly the same in 2008, but in 2005, you can open up SQL Management Studio, right-click on the dbase you'd like to copy, and then click on Export Data.
This will guide you through a wizard, allowing you to export the data to another SQL dbase, including one that runs on your local machine. Used it many times - works great.

Why don't you just do a backup and restore?

Related

Hangfire on Windows Server 2019 with SQL Server 2019 Express

I'm trying to move to a new hosting provider and I'm having real difficulty getting my web site to run. It uses Hangfire on application startup to run some background jobs, whilst also serving web pages on the main thread.
The website seems to work for the very first page load and then subsequent accesses fail to run a reasonably complex Entity Framework search query.
Here's the server's configuration on the existing machine, via SQL Server's select ##version command:
Microsoft SQL Server 2017 (RTM-GDR) (KB4583456) - 14.0.2037.2 (X64) Nov 2 2020 19:19:59 Copyright (C) 2017 Microsoft Corporation Standard Edition (64-bit) on Windows Server 2016 Standard 10.0 <X64> (Build 14393: )
Shared operating system (not sure what this is)
SQL Server 2017 - Standard Edition
.NET Framework 4.8
Hangfire using SQL Server storage, with table's using the Hangfire schema
Other application tables, with tables using the dbo schema
Here's the server's configuration on the new machine, via SQL Server's select ##version command:
Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Express Edition (64-bit) on Windows Server 2019 Standard 10.0 <X64> (Build 17763: ) (Hypervisor)
Windows Server 2019
SQL Server 2019 - Express edition
.NET Framework 4.7,. (according to Plesk, although I've installed 4.8)
On the new server I have full RDP access, so can install whatever software I like on this machine. However, SQL Server Standard edition is extremely expensive for a little website like mine.
Is there something that is preventing the Entity Framework query running on the new Windows Server 2019 machine, with SQL Server Express? Does that combination not allow multiple schemas for the database, or is there some other restriction from this combination that I might not be aware of?
Running the website with SQL Server Express on my local Windows 10 machine runs fine.
I'd really appreciate any help with this, as I'm pulling what little hair I have left out of my head!
Thanks for trying to help, but in the end the problem was a lot simpler than I'd anticipated. I thought this was a permissions issue, but actually it's just a simple performance issue.
Running SQL Express on the new server failed because the machine didn't have enough RAM. It only had 4GB of RAM, and with Plesk and other software installed by the hosting provider, the free RAM was down to just a few hundred MBs.
Some simple queries that would take milliseconds to return on the old server could take over 2 minutes to return on the RAM limited new server.
Increasing the RAM to 8GBs fixed most of the issue, although using SQL Express is still significantly slower than the SQL Standard edition on the old server, and SQL Standard is alarmingly expensive to run just for this one website (the old server has a shared SQL Standard edition installation).

SQL Server Database Mail Error/Missing

Current SQL Server:
SQL Server 2016 Express SP1
Microsoft SQL Server 2016 (SP1-CU7-GDR) (KB4057119) - 13.0.4466.4 (X64)
Dec 22 2017 11:25:00
Copyright (c) Microsoft Corporation Express Edition (64-bit) on Windows 10 Pro 10.0 <X64> (Build 15063: )
Downloaded Cumulative Update 1 and went through the installation steps
Downloaded Microsoft .NET Framework 3.5
Database Mail still does not show. Suggestions?
Of note, when I click on the download file for Microsoft .NET Framework 3.5, it doesn't do anything even when trying to run as an Administrator.
Thank you!
http://www.sqlservercentral.com/blogs/querying-microsoft-sql-server/2013/09/02/sending-mail-using-sql-server-express-edition/
In SQL server standard and enterprise edition,A DataBase mail functionality in built to sent mail.But in SQL Server express edition,You need either use CLR integration or configure SQL Mail using MSDB system database.
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/cd59b9cc-21ea-4130-afd1-791124031ada/can-sql-server-express-send-emails?forum=sqlexpress
You can make use of CLR Integration for sending email from SQL Server Express.
http://www.sqlservercentral.com/articles/SQL+Server+Express/71341/
http://www.vnypatel.com/sending-emails-with-clr-sql-server-express-editions
SQL Server Express does not support database mail.
https://msdn.microsoft.com/en-us/library/cc645993.aspx

Cannot restore CDC-enabled DB on Express Edition

While restoring database I got this error
SQL Server cannot load database 'XXX' because Change Data Capture is enabled. The currently installed edition of SQL Server does not support Change Data Capture. Either disable Change Data Capture in the database by using a supported edition of SQL Server, or upgrade the instance to one that supports Change Data Capture.
Mine SQL Server
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (Intel X86) Jun 28 2012 08:42:37 Copyright (c) Microsoft Corporation Express Edition with Advanced Services on Windows NT 6.1 (Build 7600: )
I know there is no feature of CDC in Express Edition but i got XXX.bak file which i need to restore on my sql server. Is there any way of script to remove CDC feature from the file?

SQL Server "Index Usage Statistics" report causes "incorrect syntax near ')'"

In SQL Server 2008 R2 Standard Edition:
SELECT ##version
Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64) Jun 17 2011 00:54:03 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1)
with non-express edition tools:
Microsoft SQL Server Management Studio 10.50.2500.0
Microsoft Data Access Components (MDAC) 6.1.7601.17514
Microsoft MSXML 3.0 6.0
Microsoft Internet Explorer 9.0.8112.16421
Microsoft .NET Framework 2.0.50727.5448
Operating System 6.1.7601
running on Windows Small Business Server 2011 Standard 64-bit:
Against a database in SQL Server 2000 compatibility mode:
If I try to run the Index Usage Statistics report I get the error:
How to make it go away?
I threw in every red herring I could think of. There should be enough extraneous information that everyone can throw out a theory.
The various reports in SQL Server Mgmt Studio make use of DMV (dynamic management views) like the sys.dm_db_index_usage_stats to fetch their data.
Those DMV are only available if you're running on compatibility level 90 (SQL Server 2005) and up. You won't be able to get this to work if you're stuck in SQL Server 2000 compatibility level (80), unfortunately.

SQL Server 2008 R2 Express: MDF file not attached in SQL Server 2008 Developer

I use this command on both express and developer addition
select ##VERSION
Express server result is below
Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86)
Apr 22 2011 11:57:00
Copyright (c) Microsoft Corporation
Express Edition with Advanced Services on Windows NT 5.1 <X86> (Build 2600: Service Pack 3)
and developer result is blow
Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
Jul 9 2008 14:43:34 Copyright (c) 1988-2008 Microsoft Corporation Developer Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 3)
When I try to attach the MDF file from my Express edition to my developer edition, I get this error:
An exception occurred while executing a
transact sql statement or batch the
database 'example' cannot be opened
because it is version 661. This
server supports version 655. A
downgrade path is not supported could
not open new database 'example' create
database is aborted. Microsoft Server,
Error: 948
Since your version of Express is newer than your version of Developer, you will not be able to migrate directly, but you have a few options, in my order of preference:
Upgrade to SQL Server 2008 R2 Developer Edition - by far the simplest approach
Use a third party product to replicate schema and then the data (e.g. Red Gate SQL Compare / SQL Data Compare - I blogged about several other options here).
Use a manual script, such as this one from Jonathan Kehayias
Use the import-export wizard from Developer Edition to pull the data/schema from Express
This is the problem of your sql version. You have created database in another version and the version in which you are trying to attach is different and old.
What you can do is create a backup file, and create new empty database and then restore that backup in it.
Note: While restoring, after providing backup file, see on left side, there is "options", click it, and then in there, you must select overwrite option, other wise it will give you structure error that the database backup that you are trying to attach has different structure than the database in which the backup is being restored.
Since SQL Server does not allow downgrading you can create a backup of your database in SQL Server 2008 instance and use third party tools, ApexSQL Diff and ApexSQL Data Diff to restore the backup from an older to a newer version of SQL Server.
You can read detailed explanation of the process in this article:Restoring SQL Server database backup to an older version of SQL Server
Hope this helps
Disclaimer: I work for ApexSQL as a Support Engineer

Resources