Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Database in VS 2015 SQL Server Database Project

I recently had troubles Importing a Database from a SQL Server Database Project in VS 2015. Just hoping this helps some folks. I will add more pictures when my rep is higher.

Error I get: The server version or database compatibility level is not supported.

This is the Error I get when I right click on the project and try and Import a Database. Import Error:

like image 756
Derek Escue Avatar asked Apr 13 '17 16:04

Derek Escue


People also ask

How do I Import SQL files into Visual Studio 2015?

Right-click your project in Visual Studio and select Add → Existing Item. Then you can find the SQL file and click the OK button to add it into your project.

How do you connect a database to a project?

Right-click on the project and select Publish. The Publish Database pane appears where you need to check the Target Database connection. Also, make sure that you check the checkboxes that say Register as a Data-tier Application.


2 Answers

Start

Right click on the Project and clicking View in Object Explorer. Step1

Add and connect to your database next, if needed. Right click on the database you are wanting to import and click Create New Project. Step2

Change settings if needed. Then Click Start Step4

like image 64
Derek Escue Avatar answered Sep 23 '22 21:09

Derek Escue


Once you open Visual Studio – go to the menu: File -> New -> Project. A new window will be opened and then find the project type: SQL Server Database Project. Having an empty database project you can either create new objects and create a new database from scratch or import existing ones. Please follow the below steps:

  1. Create a new SQL project in the Visual Studio solution
  2. Right-click the new SQL project and choose Import -> Database
  3. Select the database you want to import and click Start
  4. Repeat steps 1-3 above for the History database (IF available)
  5. Add a database reference to the main database that points to the history database a. Database reference to a project in the current solution b. The database location is “different database, same server” c. Replace any periods in the Database variable with underscores. Periods are not supported in the variable name.
  6. Right-click the main SQL project and go to Properties -> SQLCMD Variables a. Add the name of the History database to the Local column of the entry for the History database (something like “Database_History”)
  7. Replace all instances of the History database name with the History database variable a. This occurred at the bottom of the table scripts, where the triggers were generated. b. The correct syntax should look something like this: [$(Database_History)].Schema.TableName
  8. Ensure both SQL projects will build successfully a. There were some cases where I had to explicitly specify the table in which a column appears (ex. ImageID -> REPORTS.Image.ImageID in a stored procedure) b. There were some instances where a stored procedure or a view referred to a column that no longer exists i. Change the Build Action to None c. There were some instances where the project wants to create users for people who are no longer with the company. i. Change the Build Action to None.
  9. Check for differences between the Visual Studio project and the deployed database (if any development happened between you importing the database and finishing the steps above) a. Generate a publish script targeting the deployed database. Anything the script attempts to modify is a difference you should obtain from the deployed database. i. Do not revert any changes made in step 8
  10. Publish the databases to an existing deployed location and ensure functionality remains.
like image 33
Raj Avatar answered Sep 23 '22 21:09

Raj