SQL Server : designer incompatible generate script - sql-server

We have a SQL Server 2012 for our test box, and a SQL Server 2005 for our production box. Recently, we moved to automated deployment scripts which execute SQL scripts as part of our deployment process.
We encountered an issue whereby the script generated by SSMS, using "Generate Script" in the designer, outputs a script that was incompatible with SQL Server 2005. It added statement SET (LOCK_ESCALATION = TABLE) which is SQL Server 2008+
We have tried changing the compatibility of the database to SQL Server 2005 but this did not resolve the issue. Interestingly, when using Script Table As > Create To > New Query Window, this statement is not included.
There is a SSMS setting "Match script settings to source = false", but, this requires you to set a SQL Server Version globally, which is not an option for us as we maintain a variety of SQL Server versions. Is there a way we can downgrade the "Generate Scripts" compatibility?

When running the "Generate Scripts" task in SSMS, you can define what server version to create the script for:
That should ensure no commands or options are used which are not present in SQL Server 2005.
But I second #ADyson's sentiment - SQL Server 2005 is beyond dead and buried and it's a risk to run production code on such an old version of SQL Server ...... you really should upgrade to a more recent version ASAP!

Related

An iIssue with SQL database attachment via Visual Studio

Me
An SQL newbie
My tools
VS Community 2017 v15.9.3 / C#
SQL Server 14.0.2002.14
SSMS 14.0...
What I want to do
I have a file, you say mydatabase.mdb, I am trying to create a connection to the database on SQL Server to access to it.
The database is not actually attached to SQL server, so I try to create my connection and attach it (correct?) using Server Explorer window on VS. I right click on "data connection" then choose "add connection"; in the "add connection dialog" I select the datasource "Database file of Microsoft SQL Server" and I give it the pathname of my file. Finally I hit "Test Connection".
The problem
On "Test Connection" I got this message:
The database 'mydatabase.mdb'cannot be opened because it is version 869. This server support version 852 and earlier.
Could not open new database 'mydatabase.mdb', CREATE DATABASE is aborted.
An attempt to attach an auto-named database for file 'mydatabase.mdb' failed. A database with the same name exists, or specified file cannot be open or it is located on UNC share
My attempts
I connected the databse to SSMS. When I asked DB version to SSMS, I got: SQL Server 2016 (130). It is not congruent with MS error report. Anyway I changed database version to 2014, then I detached it from server and try again: same result.
Last note: if I create my connection on attached (by SSMS) database, and specifing directly the SQL server (not the file) as datasource, it seems to work. I could use this way, but I'd like to know the cause of the problem.
Can anyone help me?
You may have installed VS 2012, but you are using a SQL 2008 instance: Visual studio does not install SQL for you.
SQL Server 2008 databases are version 655. SQL Server 2008 R2 databases are 661. You are trying to attach an 2008 R2 database to an 2008 instance and this is not supported.
You need to upgrade your SQL instance to at least 2008R2 to open the file (but be aware that if you subsequently attach your existing DBs to the new instance, you won't be able to open then in SQL 2008 again either)
Your SQL Server version (the server that reported the error) is 2016, that is, it supports db version 852 and earlier.
The database that you try to attach is of version 869, this means it was created on SQL Server 2017.
You cannot attach it to an earlier version of SQL Server, so you need to upgrade your server to 2017 or install another instance of SQL Server, SQL Server 2017.
P.S. You CANNOT downgrade database version, i.e. when you said
I changed database version to 2014
it is not true.
Maybe you just change the compatibility level of database, but it's version is still 869.
Compatibility level means a version of cardinality estimator to use + some features, it has nothing to do with database version that refers to physical file format. Database version cannot be downgraded, only upgraded.
P.P.S.
I connected the databse to SSMS
You cannot "connect database to SSMS", you are connecting to server, and the database is also attached to server. And if you were able to attach this database to SQL Server, this means you have SQL Server 2017 already installed.
P.P.P.S. To detect your SQL Server version you shopuld execute this code: select ##version (from SSMS). It seems that you have at least 2 servers, 2016 and 2017 on your pc. You can verify this by opening SQL Server Configuration Manager, or you can use Windows Services to determine how many instances you have and what are their names. Then all you should do is to use the correct instance.
Here is the picture of my SQL Server instances, you can verify your instances by launching services.msc on your pc.

Cannot restore a database with a .bak file due to another SQL server version

I have installed SQL server 2008 R2 and i try to restore a database a colleague sent me in a .bak file.
Unfortunately, i cannot restore the database since the database was saved on a server from version 10.50.1600 and my SQL server version seems to be 10.00.1600.
I tried to upgrade my SQL server with SP1 and SP2 packs but it didn't change anything.
Otherwise, i noticed by clicking on the server property that the line "product" displays Microsoft SQL server Express edition even though i have installed SQL server 2008 R2. That's at least what is displayed when i fire it...
Can anyone help me ?
Thanks in advance
You CANNOT do this - you cannot attach/detach or backup/restore a database from a newer version (SQL Server 2008 R2 - 10.50.1600) of SQL Server down to an older version (2008 - v10.00.1600) - the internal file structures are just too different to support backwards compatibility.
You can either get around this problem by
using the same version of SQL Server on all your machines - then you can easily backup/restore databases between instances
otherwise you can create the database scripts for both structure (tables, view, stored procedures etc.) and for contents (the actual data contained in the tables) either in SQL Server Management Studio (Tasks > Generate Scripts) or using a third-party tool
or you can use a third-party tool like Red-Gate's SQL Compare and SQL Data Compare to do "diffing" between your source and target, generate update scripts from those differences, and then execute those scripts on the target platform; this works across different SQL Server versions.
Understand, what the version numbers mean. You need to be on R2 which is not just a patch or service-pack.

Alternate option for SQL Server 2008 Management Studio Express

I am trying to install SQL Server 2008 Management Studio Express found here, but I am getting a win32 not an application error.
Is there another option for managing Windows SQL Server databases other than Visual Studio? I just have to be able to log in to the server and run some test SQL like:
ALTER TABLE test ADD column VARCHAR(50)
Can you run that query in Visual Studio? If so that would solve the problem too.
There is the command line sqlcmd utility.
The sqlcmd utility lets you enter Transact-SQL statements, system procedures, and script files at the command prompt, in Query Editor in SQLCMD mode, in a Windows script file or in an operating system (Cmd.exe) job step of a SQL Server Agent job.
Yes, you can run ad-hoc queries to a SQL Server database from Visual Studio.
Find/create a Data Connection in Server Explorer, right-click, and choose New Query.

How can I get a SQL Server 2005 compatible backup from SQL Server 2008 database?

I have a sql server 2008 db, I want to restore its backup to a 2005 version. Is there any way for this work?
Note: I can't make a script from my db and run it.
No. It is not possible to restore a database from a backup of a newer version.
The only solution I have come accross is generating a script, but it seems that you do not want to use this
Unfortunately, SQL Server has never supported this - and still doesn't :-(
There is no way you can create a backup in a newer version and restore it in a previous version - and this goes from SQL Server 4.2 all the way through 2008 R2.
All you can do is either create scripts and run them on the target server, or use tools like SQL Compare and SQL Data Compare to compare the two databases and update the target database from the source (basically, what these tools do is create and execute the necessary scripts in the background, so you won't have to fiddle and create those scripts yourself)

Is SQL Server 2008 compatible with 2005?

I have a problem with my website. When I publish my site on server, I got an error message:
The database '----------------------------.MDF' cannot be opened because it is version 655. This server supports version 611 and earlier. A downgrade path is not supported.
What can I do about this?
You can't push a 2008 mdf file into a 2005 server. It just won't work. The problem is that sql 2005 has no idea what features you may have used in the 2008 database which doesn't exist under 2005.
Your only real option is to:
1. Create a blank database on the sql 2005 server.
2. Script your tables, views, procs, functions, etc from the 2008 server.
3. Run that script on the 2005 server.
IF you used some advanced features, then the 2005 server will not be able to run the script. Fix what you have to.
Yes... in SQL 2008, generate scripts for your DDL and DML; the vast majority of the scripts will be compatible, but you may need to make the odd tweak to accommodate SQL 2005.
Upload and run on your SQL 2005 instance...
There maybe a number of 3rd party tools that can aid you, particularly to generate the insert statements.
If your DB is particularly large, you might want to is SSIS to move the data across.

Resources