How to get rid of localdb in SSDT? - sql-server

I am unable to use my database project after migrating from VS2010 to 2012.
All scripts for the database objects in the project are connected to the automatically-created localdb database. I am not interested in localdb since the database is large and I maintain it in a full-blown instance of SQL Server 2008 R2.
I tried all possible settings in Tools-Options-Database Tools-Data Connections-SQL Server Instance name to no avail. After re-loading the projects, it always restores the same connection to localdb.
My problem is that I need to refer from one database to another. I do it with synonyms:
CREATE SYNONYM [pcg].[practice] FOR [PcgDb].[Portal].[practice];
This script is automatically linked to localdb and the PcgDb on localdb has no tables. Hence I an getting an unresolved reference error 71501.
I tried also all combinations in Add Database Reference, even added my instance of SQL Server to the localdb linked servers, still the same error.

When you first create the SSDT project, the first step should be importing the target database; at that time you can specify you live instance of SQL Server. You shouldn't need to "get rid of" the local DB, it should just be ignored at that point. Perhaps this is happening since you migrated an existing 2010 project? In that case I would suggest you just create a new Project and do the import from the live server.

Related

How to export the localDb to an online Sql Server Database?

I used visual studio 2013 for developing a web application and used a localDB in development phase, now I want to go to production phase and want to export the sql server localDb to the online SQL server database, but I cannot find any option to script out the localDb or migrate it?
Which tools I can use to do this ? or what I must do?
There are atleast two routes; you could publish and recover as Data Tier Application:
Or, the easier-but-lengthier route would be to:
Create a new DB in the SQL Server Management Studio (Naming it the same as LocalDB is helpful if you just want to change the connection string later)
Right-click database on SQL Server Object Explorer and select Schema Compare
Click Select Target and navigate through Select Target Schema(Dialog) > Database > Click on Select Connection > Connect(Dialog) > Browse > Local > Database Name > Select the Databse you created in Step-1. Then, click OK
Click Compare or, hit Shift+Alt+C
Then, the Schema Comparator tells you whats different between the two databases (the one from MSSqlLocalDB and the one you just created in Step-1). It is important to remember unchecking ANY entries for delete operations, if you are simply transferring data and schema. Keep add operations as it is.
Then, click on ↑UPDATE (the option is located right beside Compare)
Your Target database should be updated
You can attach the localDb to SQLServer 2005 or higher and then you can generate scripts or export data to remote server.
Or
If LocalDb is SQL Server 2012, use SSMS 2012 or later for this scripting task.
Unfortunately VS2013 does not has any feature to script out a localDb, I waste so many time to copy table by table scripts, and run it at remote db. my local db id sql v11.0 (2012 I think). and the remote db was sql server 2008. so one way exist is to install an instance of sql server 2012 and sql server management studio to script out my db. maybe another tools also exist it is very sad that vs has not this feature.

How to use SQL Server Database Project

I am running SQL Server 2012 and VS 2010 with SSDT (SQL Server Data Tools) installed. My dev DB uses stored procs, functions, CLR objects, etc. It has a snapshot of prod data of about 500GB.
I created SQL Server Database Project and then imported the database. This created all tables, views, procs and functions files under schema names. Great stuff -- now I can do a version control just like in other VS projects, create deployments, etc. So far, so good.
But, I am confused as to what my development process should be for changing/adding procs/tables under SQL Server Database Project. It appears that any changes I make are applied to some LocalDb/Projects database and NOT to my dev database.
Am I suppose to author all my objects in that LocalDb, then Build and deploy to my dev database via Publish? I am worried about my existing tables in the dev DB since if the publish process drops and recreates tables, I will loose my prod data snapshot.
What is the right development process to follow in SQL Server Database Project?
Think of the source database (in your case, your database project) as being the "to be" state after deployment. When a deployment is initiated, the executable (SqlPackage.exe) compares the source with the target and generates a difference/delta script to make the target look like the source. This is why we no longer have to specify CREATE or ALTER; the tool figures it out. To answer your question about ongoing development, you can develop either way. You can develop in the project files and publish them to a common Dev database (say, if you're on a team), or you can develop in the database with tools like SQL Server Management Studio (SSMS) and synchronize with the project files with a schema compare (I use the latter technique because I like SSMS).
For deployment, you'll have to have SSDT installed on the machine from which you execute the deployment (SSDT ships with SQL Server 2012 and later; I don't know about SQL Server 2008). You can create scripts to simplify deployment. You'll essentially call SqlPackage.exe (it lives in x:\Program Files (x86)\Microsoft SQL Server\nnn\DAC\bin) with an action and a source. I use Publish Profiles as well to take care of most command properties. So an example deployment might look like this:
SqlPackage.exe /Action:Publish /SourceFile:MyDatabase.dacpac /Profile:MyProfile.publish.xml
For more information:
SQL Server Data Tools Documentation
http://msdn.microsoft.com/en-us/library/hh272686(v=vs.103).aspx
SqlPackage.exe Documentation
http://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx
Make changes inside the VS DB project.
Deploy changes to localDB to test
Publish the database to your production server. I prefer to use Schema Compare to do this manually, but you can also publish the project via the right click --> publish menu (which will also create a publishing profile), or using command line arguments. The publish process won't drop and create tables (unless you tell it to drop & recreate the entire db).
Alternatively, in the project settings you can change the connection string to point to your production server (as pointed out in the comment). However, I recommend against this, as it will then attempt to publish to the production server every time you run a local build (F5).

Importing Objects into a Visual Studio 2010 Server Project

I'm trying to reverse engineer my database via the SQL Server Wizard in the VS2010 database project template. I'm able to RE my database, but it's not enough, because in order for my sprocs to compile without errors and warnings, I need to have my linked servers and their logins included also. However, my DBA's can't give me the required VIEW ALL DEFINITION permission on the SQL Server in order to run that wizard at the server level. They don't want to do that for me in VS2010 so I am stuck. Has anyone had success compiling or found a work around for using the database level database project and using linked servers and other server level objects?
Developers can create an empty server project. You can then have your DBAs populate it via "Import Database Scripts and Objects" command. Just have them right-click the server project and they'll see that as the top command.
Your database project then should add a reference to this server project, and you should be all set.
Microsoft designed database projects on the assumption that only a DBA will import objects. For instance, in importing a SQL Server 2008 database, if you don't have "VIEW DEFINITIONS" privilege, you'll get an error about attempting to import user encryption keys. You'll get this error even if there are no user encryption keys! They assume only a DBA will do that.
Read and vote on Schema Compare permission error for Database Encryption Keys even though the type is set to be ignored if you would like to let Microsoft know what you think about this issue.

DB cannot be opened because it is version 655. This server supports version 612

I'm trying to do some excercises from exam 70-515. Unfortunately I fail while trying to attach Northwind to a grid-control. It would result in:
NORTHWND.MDF' cannot be opened because it is version 655. This server supports version 612 and earlier. A downgrade path is not supported.
I use Windows 7 Home and MS Visual Web Developer 2010 Express. As fas as I understand this error, SQL Express must be an old version on my system. I downloaded and installed SQL Express 2008r2 from here. No effect. From other sources I figured out that I might need to change the instance name: Tools -> Options -> Database Tools -> Data Connections -> SQL Server Instance Name. There it is written SQLEXPRESS. I don't know what else I should insert there?
Turns out that deinstalling SQL Express and reinstall the latest version fixed the problem. I chose SQLSERVER2008 as Instance-Name while installing and set it in Visual Studio as described above.
Go to the Services control panel and look for a service named SQL Server (XXX) -- that XXX is the name of the instance that service is running. You just have to find the 2008R2 instance that you installed and type that into the "SQL Server Instance Name" box.
Might help to try to change the compatibility level, to make sure its backwards compatible.
Verify what level it is
USE VJ_DATABASE;
GO
SELECT compatibility_level
FROM sys.databases WHERE name = 'VJ_DATABASE';
GO
Then make it compatible with the older version
ALTER DATABASE VJ_DATABASE
SET COMPATIBILITY_LEVEL = 110;
GO
100 = Sql Server 2008
110 = Sql Server 2012
120 = Sql Server 2014
By default, Sql Server 2014 will change the db versions compatibility to only 2014, using the ## version you should be able to tell, which version Sql Server is.
Then run the command above to change it the version you have.
Additional step: Ensure you look at the accessibility of the DB is not reset, do this by right clicking on properties of the folder and the database. (make sure you have rights so you don't get an access denied)
I read this post but nothing helped me. Then I tried a few other options.
The way that I found that worked was to export the database and stored procedures from the original database. Then upload them into the second database(second computer).
Firstly export the DB content (data) - I used SQL server export data wizard. on the database you wish to export from right click then choose tasks, then export data. Follow the instructions and save in whichever format is best for you - I used excel for the data.
then to export the stored procedures rightclick the database name again. choose tasks and this time choose generate scripts. again follow the instructions of the wizard.
To import the data simply go to the second computer and right click the database you wish to import the data into. again tasks > import data. Follow the instructions to import all of the data from the database.
Finally to import the stored procedures, I opened up a new stored procedures command and dragged and dropped the script file that I had previously saved them in and dropped it into this window. The new stored procedure window filled with the entire list of my stored procedures. Finally change the name of the database name that will be used by the SP ( if this is different from the original DB name). (This is the first line USE [DBName]. then simply execute and the SP's will be fully restored.
This has helped me get my entire database up and running again very quickly. Hope this helps.
The SQL Management Studio is different than the SQL Server Version (or Database version). Example: At the current time, my work computer has SQL Server 2012 Management Studio but the SQL Version is 9.0 – which is SQL Server 2005. The SQL Management studio is only an IDE (Integrated Development Environment) and is NOT the same as the SQL Server version.
If when you try to Attach a Database, if you get an error similar to the following:
“The database 'AdventureWorks2008' cannot be opened because it is version 655. This server supports version 612 and earlier. A downgrade path is not supported.
Could not open new database 'AdventureWorks2008'. CREATE DATABASE is aborted. (Microsoft SQL Server, Error: 948)”.
It means that the Database that you are trying to Attach was created with a Newer SQL version then what your computer has and you will NOT be able to use it. See if they have that Database that was created with the same or earlier version of SQL Server that your computer uses. In this case, I found the same Database that was created with SQL Server 2005 (Version 9).
A quick way to check what SQL Server version the computer is running, from the Windows desktop, go to Task Manager (Ctrl+Shift+Esc), click on the Processess tab, find and select the entry named “sqlservr.exe”, right click and choose Properties, click on the Details tab look at Product Version (Ex. 9….) or File Version (File version states the year and the version - Ex. 2005.9…).
Really this is the same error that i get, but until now i did not solve the problem!!
Go to Tools>Options>Data Connections, provided you have installed SQL Server Express 2008r2, leave the SQL Server instance name blank.
This happens when you are trying to use the SQLServer Express to connect to the MDF file. To remedy this issue, you need to go to Services.msc and turn on SQL Server services. You need to set the log on properties and when the service is started, you will be able to connect to the MDF file without any issues.

ASP.NET MVC Tutorials using SQLServer?

How can I use SQLServer (instead of SQL Express) as my database?
I'm trying to go thru the ContactManager tutorial, but I can't seem to get it to use SQLServer - when I pick SQLServer from the "Add New Item" dialog, I get an error telling me that SQL Express isn't installed.
I know I must be missing something basic...
Most tutorials on the ASP.NET site are written in such a way, that you don't have to buy any software to do them. They use Visual Studio Express and SQL Express in their examples.
However, You can still follow along with the tutorial. Just make a few adjustments. Go to the Server Explorer to create a Connection to your SQL Server, and create the database and tables.
Then when it comes to the step of creating the EntityDataModel, create a new connection to the database you just created.
Only SQL Express can attach your database at runtime. If you have a non express version of SQL Server you will need to create the SQL Server using SSMS. If you want the file to physically live in app_data then when asked where to put the database file and the ldf indicate the app_data folder. Once you have created it, it is easy enough to simply add it as an exsisting item, although it can't be checked into source safe without creating obvious issues. I hope this helps.
If you're using a full-fledged instance of SQL Server, you don't need to use the "Add New Item" dialog at all. Rather, connect to your SQL Server instance (via Visual Studio or SQL Server Management Studio), and create the new database there.

Resources