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:
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.
Right click on the Project and clicking View in Object Explorer.
Add and connect to your database next, if needed. Right click on the database you are wanting to import and click Create New Project.
Change settings if needed. Then Click Start
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:
- Create a new SQL project in the Visual Studio solution
- Right-click the new SQL project and choose Import -> Database
- Select the database you want to import and click Start
- Repeat steps 1-3 above for the History database (IF available)
- 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.
- 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”)
- 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
- 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.
- 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
- Publish the databases to an existing deployed location and ensure functionality remains.