Accessing Visual Studio Database Project Schema Programatically - visual-studio-2010

I'm trying to find a way to access the schema of a database project programatically from within Visual Studio 2010.
For example, if I have a solution containing a SQL Server Database Project which defines tables, views etc, and Visual Studio displays those objects within the schema view, I'd like to be able to enumerate the objects in the schema view.
Can anyone provide some tips or a link? Thanks.

Here is a starting point on MSDN. The "Create Custom Features for Database Projects" part is probably relevant for you.

Related

Database Schema Viewer functionality in vs2013

Recently migrated from vs 2010 -> vs 2013. Observed that there is no Database Schema Viewer in vs 2013 for DB projects. SQL Server Explorer does something similar but when you add new items (say a new table) to a project, noticed two things:
1. the new table file gets created in the root folder and not under the Schema Objects\Schemas\dbo\tables\
2. In vs2010, the table scripts used to have extension XX.table.sql but in vs2013, its always XX.sql
What actions can i take to achieve the above 2 behaviors as in vs 2010
Schema View is no longer part of Visual Studio. You'll have to use a 3rd party tool. If you have SQL Server Management Studio then you can use its database diagrams feature.
Visual Studio no longer manages the folder structure in database projects. When adding a new item, you should add it to the appropriate folder yourself.
To include the schema name in your files go to the database project's properties, select the Project Settings tab, and check Include schema name in file name. This change is not retroactive.

Reload database objects in a VS database project?

if I create a SQL Server 2008 Database Project in Visual Studio 2010, then I am able to right click the project and select Import Database Objects and Settings.... I can do that exactly one time (even if I get an error while importing). If I did it one time, the option is grayed-out.
But after I have imported my objects, I couldn't find a way to reload or refresh the objects. A good example would be, that I have a database project of a whole database and someone adds something to the database directly. Now I want to have new table (function, procedure, etc.) in my project, too.
There has to be a better way than copy&paste to add new existing database objects to my database project?
I found this question:
Script all SQL database objects into VS Database project
But I neither have a Schema Compare option, nor can I drag&drop files from the server explorer.
In Visual Studio you should see a menu choice that says Data. If you click on that, you should be able to run a Schema Compare. If you're not seeing that, then there's something wrong with your VS install or the project or maybe both.

Database in version control using Visual Studio 2010 Professional

I've added a SQL Server 2008 database project to my Visual Studio 2010 Professional Edition solution in the hope that it might allow me to include my database in version control.
I can commit the schema files for each database object into version control, however these schema files all script objects as create rather than alter, so are not good for colleges getting my changes and updating their databases.
Is this a good way to get my database into source control?
And what would the workflow be for actually using it to update databases to a given revision without losing all the data associated with dropping and re-creating all the tables?
Update: on Premium and Ultimate versions, there is a schema compare tool which makes this easy. This does not exist on Professional. Is there any straightforward manual workaround?
I'm not sure if you can do this in VS 2010 Professional, but in VS 2010 Premium, you can do a schema comparison (Data -> Schema Compare -> New Schema Comparison) between your project and database, and update changes in either direction.
When going from project to database, VS generates a script that copies existing data into a temporary table before dropping the existing one.
The database project has a deploy step (which is present in my Professional copy of VS2010) that will generate a sql script with your sql objects in it.
The key thing here is if you r-click the project, properties, goto deploy and change target database settings to a specific database, when you deploy it will generate a change script for that specific database so it matches the objects in the project (and in theory keep existing data etc).
You can get it to either generate a sql script, or directly update the database. Generating a script is probably a better idea :)

Database project deployment

I have database project in visual studio 2010. It has tables views stored procedures etc. I have created a full text index on view and in stored procedure I am using like this:
create proc myproc
as
select * from my view
where contains(tblperson.fname,'Steve')
end
When I deploy, I get error that I can't use contains as view is not full text indexed. I want to know if there is a sequence in which database project is deployed ? means first stored proc is deployed or views are deployed. Can I change this sequence.
Please suggest.
The Visual Studio Database projects are great! I have just migrated from Db_Deploy integrated with SVN to TFS Visual Studio Database projects. The database projects work by creating a self contained db schema file and when you use the VsDbCmd command for deployment, it will do a schema comparison between the project schema and the database schema to generate the delta script for you. The order in which the comparison takes place is Tables, Procs then Views, ...
I would suggest that you apply this script direct on to the database and then use the schema comparison from database to project to soak in the changes. This way the visual studio database project will create the script for you. Read more about the db comparison and walkthrough on msdn http://msdn.microsoft.com/en-us/library/aa833435.aspx.
PS - How are you managing deployments of your db project? I have automated the entire deployment suit, interested to know how others are doing it.
HTH.
Cheers, Tarun

SQL Server Management Studio solution vs Visual Studio Projects

Almost all of our projects involve a web application or winforms application and a data access layer (class library) and stored procedures/database scripts.
We are looking for a good way to organize the solutions, and found a few ways:
1)We could have a sql server management studio solution for all the db related things, then have a visual studio solution for the application and data access layer projects.
2)We could do it all in visual studio with 3 projects, a sql server project, a web app/winforms app project, and a data access layer project.
3)We could do it all in visual studio with 2 projects, a web app/winforms app project and a data access layer project, and just put the sql scripts in a directory in the data access layer project.
I'm sure there's other ways, but I'm just curious to see how others go about doing it.
I have done this successfully using Visual Studio Team System Database Edition - multiple types dot net projects with a database project in a single solution.
Keep in mind that deploying a database project takes much longer because you usually need test data and most inserts thereto are RBAR insert statements. We used to turn off deploying the database project until absolutely necessary (usually once or twice a week).
Of course, all of this was in TFS for source code control
SQL Server Management Studio solution
allow use GUI designer for creating and editing some objects.
Visual Studio Projects
allows use TFS as version control and more integrate work of all developers working with a database;
better implements IntelliSence
I use Management Studio and some batch files to export/import/store the sql in the solution (under source control too).
So each time there's a change in the db it's exported to the solution and a custom tool is run to update the ORM proxy classes.

Resources