How to run script generated by publish for SQL Data project - visual-studio-2013

I'm using SSDT (in SQL Data Project) in Visual Studio 2013. When I publish the database, I can
Do a direct publish (click the publish button)
Generate the script, then execute in Visual Studio
But the script does pretty much nothing (apparently) if I copy it to SSMS and try to execute it (in SQLCMD mode).
How would I execute a generated script outside of Visual Studio? Do I have to use sqlcmd.exe? And if so, are there certain command line parameters that I would need to use?
Thanks!

The comment by Peter helped me look at the issue from a new angle. It wasn't a database problem, but a table issue. The database has an auditing table for every table. I was updating the Address table (I thought), but instead updated the A_Address table. It was all working fine. The first run updated the audit table, subsequent runs didn't (of course), but I was checking the Address table for the update. Doh! New database, new technology....

Related

Oracle Developer Tools for Visual Studio 2017 (ODT)

I have created an Oracle Database Project Version 2 on visual studio 2017 and imported an existing database to the project to obtain the database schema on my project, and I got an SQLfile for such object in my project. The problem is when I'm modifying a table for example and saving the changes on my oracle database project and build it, I get a create script as output instead of an alter script so this script can't be deployed to my database due to "existing object error".
I tried to do it otherwise by proceeding to schema compare option:
I launched the schema comparison by mentionning my oracle database project as source and my database as target
The result of the comparison indicated that there is an non indentical object between the source and the target which was the table (because i added a coloumn to the table)
Again the problem is when I generate the update script it gives a drop/create table script instead of an alter and I can't deploy this script because I will lose data.
Does anyone have any ideas? how can I get the alter script by building the project or launching a schema compare operation?
I've found that comparing two databases DO generate a "somewhat" correct diff script (it may need some manual adjustment). So you can run the SQL file generated by the database project against a different oracle instance, and then compare both.

Sql Server 2008 Database Project Delta Deployment

I have created a new Sql 2008 Database Project in Visual Studio 2010. I imported the database objects and only kept the stored procedures. That all worked as expected. Where I have the problem is that it tries to deploy the entire set of procedures each time. I expect it to only create the deployment script for the delta. I am pretty sure that I combed every setting, but I can't find it. So if someone could first validate that this is possible and second tell me where to look. I need to do this because we only deploy the stored procedures with each release, the database schema is not modified.
Do a Schema compare of the project (as source) with the database where you want to deploy (as target). Once shcem comparison results are shown you have a choice to select which changes you want to deploy and then click the button "Export to T-SQL Editor". It will create the delta script.

How to re-deploy, re-create database on each test run

Currently I'm using Visual Studio 2012 RC and SQL Server 2012 RTM.
I'd like to know how to re-deploy/re-create a test database for each test run.
Keep in mind I've a SQL Server database project for the database using Visual Studio 2012's template.
Actually I'm not very sure about an idea I got in my mind, but .testsettings file has Setup and cleanup scripts. Is this the way to go? For example, a PowerShell script reading the database project generated script and executing it against the database?
I guess there're better ways of doing that and it should be an out-of-the-box solution but I ignore it and Google doesn't help me in finding the right solution.
As mentioned you'll probably want to use the VS 2012 .Local.testsettings > Setup and Cleanup scripts to create / tear down you SQL Server database.
For the script you may want to use powershell with a .dacpac (rather than just a T-SQL script), since you are using a SSDT project. Here's a link to some example code - in particular you may want to take a look at the 'Deploy-Dac' command.
If you are unfamiliar with .dacpacs as the (build) output of SSDT-created database projects, take a look at this reference link.
Edit: Although this doesn't answer the question in a plain SQL Server way, an easy Entity Framework approach would be the following: I found that I could create and destroy my database every time correctly by using the DbContext.Database.CreateIfNotExists() and DbContext.Database.Delete() methods in my setup and cleanup phases of my tests.
The fastest solution, while a bit of a hack, is really straightforward. You can set the DB Projects properties under the debugging tab to "always re-created DB". Then test in two clicks, do a debug/build, then run all tests. You should get a freshly built DB on localDB for you tests to be ran against. You can also change the target for the debugging DB (again the DB projects properties) to whatever you want, so you can deploy to a .dacpac, or to an existing SQL DB or wherever. It means testing in two steps, and if your build is long, it may be annoying, but it works. Otherwise, I believe scripting is your only option.

Attached SQL Express DB is causing problems

I have been asked to create an MVC web application in VS 2010, and was instructed to use a SQL express database for my data. I am using EF Code-First for creating and managing my data. The database was created in VS2010, and is attached via "AttachDBFilename" in the web.config.
I have used SQL CE before with MVC with no problems, however the attached SQL Express DB is causing weird issues.
For one thing, when I try to deploy the app, it fails and tells me that it cannot copy the database.mdf because it is in use by another process. I have NOT opened the database in VS2010 nor SSMS. Of course the program code accesses it - is there some reason that connection would remain open? I am using boilerplate code from the scaffolding.
I should mention that I use a ProjectInitializer.cs to create the sample data. It runs at every launch for the moment, since I am testing quite a bit.
The other problem I have is that if I delete the database, it fails to recreate it. It says that my windows account does not have access to the (now non-existent) database that it is trying to create. I literally have to create a new database with new name, as anything that was created previously (with that DB name) fails.
I assume there is some sort of residual info being left somewhere that is out of synch, but I don't know what it is. I've closed all connections to the file in VS 2010, deleted the files, both any found via VS2010 and any physical files I see in the app_data directory.
Any help or suggestions would be appreciated.
Shut down the web server (Cassini, IIS, IIS Express) and try again. The file can remain locked if the web process is still referencing the file. In addition the loaded EF context will retain the db name. Ensure the visual studio browser isn't running in the tray still either.

How to create incremental scripts to update database schemas using Visual Studio 2010?

I'm trying to use VS 2010 Sql Server Database Project to keep track on changes made on my database and to generate appropriate scripts when a change needs to be deployed from dev to production environment.
I have created my schema comparison between my dev database and the project schema which does a great job. However, I cannot find a way to create incremental scripts, the only things I get are scripts with CREATE statements (Export to Editor option).
Am I doing something wrong?
Thanks in advance.
As part of our auto build process, we store .dbschema files for each environment in source control. During the build, we create the .dbschema file based on the database project and then use vsdbcmd command line call to generate the change script between the project schema and each destination DB schema. If you need specific command line call, let me know.
If you're using "Data Dude" correctly, these are done for you and run when you choose Deploy. Just keep your schema (tables, stored procs, populate scripts etc) as a project item and change it as you need to. The build-and-deploy process will generate the scripts. http://msdn.microsoft.com/en-us/library/ff678491.aspx is a not-bad starting point if you want to get these scripts and run them youself against various staging, production, etc databases.
In the .deploymentmanifest file there are two settings:
<DeployToDatabase>False</DeployToDatabase>
and
<DeployToScript>True</DeployToScript>
Running vsdbcmd will then generate the change scripts without affecting the target database. All you'd need is a version of the database which is the same as the production version, or access to point vsdbcmd at production to generate the script.

Resources