VS 2010 database projects and tables created by "select into" - visual-studio-2010

I am trying to move an existing database into a VS 2010 database project. This database has been around for a very long time and has a lot of stored procedures. Many of those stored procedures create working tables using the SELECT ... INTO syntax. This was done at the time to reduce the amount of data going through the transaction log. When I import the database into the project I deselected the work tables. Now when I look out the warning I see all of my stored procedures are saying that they can't find the work tables. Does anyone have a way of dealing with this? I am slowing converting as much as I can to SSIS but there is some logic that will have to remind in the stored procedures.
Thanks.

In this case you either have to ignore the warnings or import those working tables that are absolutely required for the stored procedures to work. I don't think the project will build properly if the tables are not present, but are expected.
If those tables are already present in the database, you should be fine as they won't be re-created. You can slowly deprecate them as you clean up your stored procedures.

Related

Visual Studio 2013 - DB Data Compare

I know you can compare and sync data between databases in Visual Studio using SSDT. But is there a way to compare DB data in DB project vs actual DB?
We currently use RedGate to sync schema and data and normally when someone makes a data change in their local DB he syncs it with redgate project scripts and checks them in to GIT so that everyone can sync their local DBs with those redgate scripts to be up to date. RedGate became too expensive and we are looking at the alternatives and looks like Visual Studio has SSDT that allows to do these kind of things.
So I was able to create a database project in VS and import the schema from the DB so now all developers be up to date if schema changes but it doesn't have an option to do the same thing with DB data. No option to create data scripts (and add them to the database project) to compare with DB, as I said it only allows you to do data compare between DBs but not between DB and the DB project scripts, at least that's what I found so far. Is there even a way to do it so that we can include data scripts and be able to sync them with DBs?
You could check in MERGE-scripts for static tables and include them as Post Scripts.
The merge statements will ensure that your target tables have the correct rows when publishing (insert/update/delete in the merge will do this).
Make one merge script file per table, and include them all in your Post Script File.
Only difference/downside is that you can not import into the merge script, you have to type in the code to get it version controlled, or write an SP that generates the SQL Merge statement.

ODAC/Entity Framework Model Update Issues

We are looking to introduce odac into our application but I am running into a number of issues and I can't seem to find any solutions that fix our issues.
We are using an oracle database and trying to use ODAC 12c Release 1 (12.1.0.1.0) with Oracle Developer Tools for Visual Studio.
In our model we would like to have multiple schemas so we can perform cross schema queries. The schemas which we select in the filter for the database connection appear when we are creating the model. However when we try to update our model from the database only the default schema is visible. Sometimes this can be fixed by opening the relevant part of the database in Server Explorer in Visual Studio but this doesn't always work. This fix never works after we add multiple connection strings for the same model (depending on the location of the user will depend on which database the user gets directed to).
The next issue we are having is that we can't the return types of stored procedures to be auto-generate. I have tried to retrieve the column information but it is never able to retrieve the metadata. I have seen a few suggestions of modifying the stored procedures then getting the column information and reverting the stored procedures but this is something we would like to avoid. Also the suggestions don't seem to work on oracle databases (but that could be me, I don't have much experience with databases).
The final issue (this is a minor issue) is that I cannot figure out how to get the generate code to omit underscores from the classes/methods generated. This isn't a huge issue it is purely to make it easier migrating the code we have.

How do I deploy specific objects from a Visual Studio database project?

I have a Visual Studio 2010 database project and I'd like to do a partial deployment, i.e. of specified objects. Is this possible? The only options I can see are to either do a full deployment or stop after generating the script.
For example, I'm changing many tables and stored procs but not everything is 100% finished and I'd like to push out a specific stored procedure to my test database, including its permissions, etc.
I read a little bit about SQL Server Data Tools, which apparently supports this, but I'm not clear on whether I'd have to migrate my database project to use that instead (would also need the ok from team lead), or if it's simply a plugin that would allow extra functionality.
Check out Schema Comparisons. They allow you to select the objects you want to deploy. They are available without SQL Server Data Tools.
A "partial deployment" is actually a little dangerous. Consider that you will have just built your database project, your entire database project, complete with the table changes, and it has built with no errors or warnings (right?). Now you want to deploy just your stored procedure, into a database that does not have the table changes.
Your stored procedure got no errors or warnings in the context of all the changes. Are you sure it will get no errors or warnings without those changes?
You should consider a source control solution to this problem. Save a copy of your stored procedure, revert to a version of the code that matches the database you'll be deploying to, then make your stored procedure changes to that. When you deploy, you will be checking to see if the stored procedure makes sense in the context of the database you'll be deploying into.

Get cdc tables in visual studio 2012/2010 database project

I am trying to create a database project in Visual Studio 2012/2010 where I need the CDC (Change Data Capture) tables , because lot of my views are dependent on the CDC tables. I couldn't find any way to import the cdc schema/tables :(. Read in many blogs that importing cdc is not supported. Is there any work around. Please suggest
Generally you wouldn't really want the CDC tables to be created by a database project, you want them to be created using sys.sp_cdc_enable_table
If you allow the database project to create the tables in a normal manner then the CDC tables would end up existing but their Change Data Capture wouldn't actually be enabled.
Obviously you can script the calls to sys.sp_cdc_enable_table in either Pre or Post scripts, but as far as I can tell neither place is ideal.
If you put the sys.sp_cdc_enable_table calls in a Pre script changes are that not all the original tables exist (on a fresh deploy none of them will exist), or that these original tables will change shape as part of the main deploy that occurs after Pre is run.
If you put the sys.sp_cdc_enable_table calls in the Post script, you can't have Views that rely on the CDC tables existing deployed as part of the main database project deployment (not without errors or warnings in your DB project).
I would suggest not having too many views, functions or stored procs that rely on the existence of the CDC tables, but it sounds like it might be too late for that.
Side Note: Generally speaking you should be using the cdc.fn_cdc_get_all_changes_ and cdc.fn_cdc_get_net_changes_ functions rather than referencing the cdc tables directly, see Querying Change Data Capture data
However, that just moves the problem along one level to those functions not existing in your project.
Unfortunately, there doesn't seem to be a good way to have those extra views without scripting them at the same point that you script your calls to sys.sp_cdc_enable_table
(I'm honestly hoping someone else will come along with a better answer that actually solves the problem)
We came across the same issue recently in a DB project using TFS/VS for builds during the implementation stage.
As Scott correctly said, it's not a good idea to attempt to implement either cdc schema or any objects inside the project/solution, this has unfortunate consequences which you really do not want to experience!
For TFS/VS projects, you should implement a Pre-PostDeployment Script strategy, whereby CDC can be disabled during the PreDeploy process and then the instances are recreated during the PostDepolyment process.
In this way you can assured that the correct CDC instances are created uniformly.
When you consider the dependent views, again, the strategy is not difficult.
Create the view as you normally would in the project, but as a placeholder (e.g. a simple CREATE dbo.vMyView AS SELECT 1 FROM SomeTable). In the PostDeployment scripts, add a further script that executes AFTER the CDC instances have been created, with ALTER statements for those views (e.g. ALTER VIEW dbo.vMyView SELECT Col1 FROM cdc.MyCDC_CT). Remember, a view, once created, can exists even if the underlying table doesn't.

Visual Studio Object Relational Designer not generating classes for stored procedures

This is my first project where I've needed to use Linq to SQL, so far I have generally found it easy to work with. However, when adding stored procedures in the o/r designer, it doesn't generate the classes and I have no idea why.
I've tried a simple stored proc that just selects from a table with no input parameters, but still no joy. I'm assuming I've overlooked a setting or something, but I can't find the solution. Can anyone help please?
Schoolboy error. I'd updated another table at the same time and hadn't noticed an error had crept in, so it wasn't updating anything never mind the stored procedures. Once the error was fixed the code regenerated and the stored procedures were available.

Resources