duplicate a Database content into another database - sql-server

I have a database that I want to duplicate into another database.
I'm using Sql Server 2012 Express Management Studio
I tried to make a backup of the database and tried to restore it as another database, but I couldn't
It happens that I was using LocalDB\v11.0, but I had to upgrade my sql server express to the version that accepts remote connections.
But now I have two servers, LocalDB\v11.0 and .\SQLEXPRESS, my database is in LocalDB and I want it in .\SQLEXPRESS
How can I do that?
Rafael

Though I haven't tried but this shouldn't be the case. AFAIK, LocalDB\v11.0 introduced in SQL Server 2012 and you can backup/restore between localdb and sqlexpress.
if that's not working then try posting the error/issue you are getting in this post.
Anyway, you can also script your database, schema and data and then run those script locally.
See this post here for the same ...
http://social.msdn.microsoft.com/Forums/en-US/b75bef7e-13f3-4658-8d43-9df12ab4c320/connecting-localdb-using-sql-server-management-studio-express
Once you are connected, you can view the DB objects and script them in SSMS; thereafter run those same script in your sqlexpress instance.

Related

How do I create a new server in SQL Server Management Studio?

The questions is basically the title because I could not find any articles to help as they only help on how to create a new database however I cant seem to create/join my own server.
The first picture attached is what I've seen other people do in order to get in however, I get an error when i try to connect
SQL Server and SSMS are two seperate softwares. SQL Server creates a database engine on your machine and SSMS is used to visualize or perform operations on these Database Servers. You Need to install both SQL Server and SSMS. While you seem to have install only SSMS.
You Can Install SQL Server from this link
SQL Server Download
You can follow this link to SQL Server Installation Tutorial

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.

Syncing a SQL Server CE database with a regular SQL Server database

There's an Umbraco site that various people been contributing content to. It runs on a hosted domain using a SQL Server Compact edition database for the CMS. It's about to go live and I need to sync the dev database to the live SQL Server instance which is hosted by a third party.
I just ass(u)me(d) that I could attach the .sdf to my local SQL Server and use a commercial tool (Redgate/SQLDelta etc.) to copy it to the live db. This does not seem to be possible. While I have managed to attach the .sdf using Linqpad, I can't connect to it like a regular database.
The best option seems to be to script out the entire database, but this seems like an impossible task using just Linqpad (no flies on Linqpad, obviously - it isn't the tool for such a task). Any less onerous options would be gratefully accepted.
You can use my free "SQL Server Compact Toolbox" Visual Studio extension for this. It can generate a script of the entire SQL Server Compact database, that you can then run against an empty SQL Server database.
In the past I did this kind of scenario wherein I need to copy the data from the SQL Server CE to a SQL Server database. Have you tried adding the .sdf to an ODBC then linked that ODBC to SQL Server?

Problem with importing an mdf created with SQL Server Express 2008 into SQL Server 2005

The question is probably extremely easy to resolve, but I need to resolve it because I need to carry on with my project. I am using SQL Server Express 2008 at home, and I've been working on an ASP.NET MVC app that stores my DB in an mdf file in the project's folder. The problem is that the SQL Server in the Uni labs is SQL Server 2005, and when I try to open the mdf file with the VS Server Explorer,It says that the version of the mdf file is more than the server can accept.
The only option that comes to my mind is exporting the DB as an sql file, just like I've done it thousand times with phpmyadmin. the thing is that the SQL Management Studio Express is not the most usable tool in the world, and for some strange reason all the articles I could find in Google were irrelevant. Please, help.
It is not possible to attach database created on SQL Server 2008 to SQL Server 2005. The other direction is possible.
Your only option is to script the database and data and run the scripts on SQL 2005. If you have used any of new features of the SQL Server 2008, you will have to rewrite the scripts.
I haven't used it much, but right click on database -> Tasks... -> Generate Scripts... / Export Data... / Import Data... should do the job right.
Google "Database Publishing Wizard", it's a tool from Microsoft to script an entire database, both schema and data.
you can script your db and its data. then run it on the target server to create a new db that is compatible with 2005 version.
Tools like Red-Gate SQL Compare and SQL Data Compare can compare a live database to e.g. a backup file, so you could compare your SQL Server 2005 database against the SQL Server 2008 Express backup file, and move data that way.
Or you could possibly generate INSERT statements for your tables that have changed data using a tool like this one here or this one here. These can generate INSERT scripts for your tables, which you can take along and run on your SQL Server 2005 target system.

I can't use a database in SQL Azure

I am trying to use a Database in SQL Azure. I have installed SQL Server 2008. I can Login SQL Azure and can use master Database. But I can't use other Database and I can't see any things in my object explorer. It shows this error:
"USE statement is not supported to switch between databases. Use a new connection to connect to a different Database."
How can I use another database?
You cannot link to another database server from SQL Azure, whether that other database is SQL Server or SQL Azure.
I found the Solution for this problem . I install SQL Server 2008 R2. then every thing is ok...
You can first create only the database before running the whole script to create schemas & Tables.
Then manually change the database to the new DB that was created.
Run the rest of the script. Do not run Use <databasename>

Resources