0

How would one go about programmatically interacting with a Visual Studio Database Project from C# code? I would like to do the following:

  • given a live database, create a database project that represents the schema of that database
  • given an existing database project and a live database, update the database project to reflect the schema of the database

I'm pretty familiar with the components of the Data-Tier Application Framework, but I haven't been able to find anything to handle these kinds of tasks. Does anyone have any experience with these kinds of workflows? Are there Visual Studio frameworks that might expose these kinds of features?

Edit: I see that someone has voted to close this question because it is "too broad". If someone is having trouble interpreting this question, please see my bullet points above. There are two very specific tasks I would like to accomplish.

Dan Forbes
  • 2,734
  • 3
  • 30
  • 60
  • Are you looking to provide the same functionality as right clicking on dbproj in solution explorer and choosing Import? – StingyJack Mar 24 '16 at 14:29
  • 1
    To programmatically create projects in visual studio (first part) - https://msdn.microsoft.com/en-us/library/ms228767.aspx – StingyJack Mar 24 '16 at 14:32
  • @StingyJack - yes, that sounds about right. I guess I'd want to: 1) programmatically create the project; 2) programmatically import a database (importing as a DACPAC would be fine too, as I know how to generate a DACPAC from a database); 3) programmatically update the database project from a live database (as in the functionality provided by the Visual Studio schema compare tool). – Dan Forbes Mar 24 '16 at 14:32
  • #1 and #2 are fine, #3 is a bad idea - the schema compare tool isn't perfect, and there are likely things that you don't want in the DB project but do want in the DB (such as logins, passwords). It's rare that you can use the update functionality directly in any kind of non-local dev scenario. – Dan Field Mar 24 '16 at 14:35
  • Point # 2: https://msdn.microsoft.com/en-us/library/aa833173%28v=vs.100%29.aspx – JLB Mar 24 '16 at 14:36
  • @StingyJack - per the link you've provided, what would be the proper language template? When I navigate to the specified directory, I find folders for CSharp, FSharp, JavaScript, LightSwitch, SetupAndDeployment, VC, VisualBasic and Web. I am not able to find anything that looks like a database project template. – Dan Forbes Mar 24 '16 at 14:37
  • How to find templates: https://msdn.microsoft.com/en-us/library/ms185306%28v=vs.100%29.aspx – JLB Mar 24 '16 at 14:38
  • @JLB - I believe the link you provided gives instructions for manually importing updates. Per the question, I am looking to perform these tasks programmatically. – Dan Forbes Mar 24 '16 at 14:38
  • 3
    Looks like programattically they want you to build macros... https://msdn.microsoft.com/en-us/library/bb264485%28v=vs.80%29.aspx – JLB Mar 24 '16 at 14:40
  • @DanField - do you have any suggestions for accomplishing numbers 1 & 2? I appreciate your input regarding #3 and I will certainly take it into account. However, I'd at least like to see if I can get it working (imperfect as it may be) and then take things from there. – Dan Forbes Mar 24 '16 at 14:40
  • @JLB - that link looks super promising, thanks! – Dan Forbes Mar 24 '16 at 14:41
  • @JLB - I think the link that you provided for finding templates is not really what I'm looking for. Your previous link that details a workflow requiring those templates necessitates the actual path to the template on disk. The article about "How to: Find and Install Templates Located Online" seems to only be concerned with "finding" a template in the Visual Studio wizard for manually creating a new project. – Dan Forbes Mar 24 '16 at 14:45
  • So you don't see any that are like 'Database' as shown here? https://msdn.microsoft.com/en-us/library/0fyc0azh%28v=vs.100%29.aspx – JLB Mar 24 '16 at 14:47
  • @JLB - when I manually browse the Visual Studio wizard I do see it. However, in order to programmatically create the solution, I need the actual path on disk to the template that Visual Studio uses to create the solution. I don't think any of the links you've provided help to solve that problem. – Dan Forbes Mar 24 '16 at 14:50
  • 1
    So you just need the path to the potential templates? Here's where mine are stored http://dpaste.com/2TZA7TV – JLB Mar 24 '16 at 15:06

0 Answers0