{"id":3243,"date":"2012-01-05T13:46:01","date_gmt":"2012-01-05T11:46:01","guid":{"rendered":"https:\/\/ingmarverheij.com\/?p=3243"},"modified":"2012-01-05T17:24:13","modified_gmt":"2012-01-05T15:24:13","slug":"reverse-and-forward-engineering-database-in-visual-studio-2010","status":"publish","type":"post","link":"https:\/\/ingmarverheij.com\/en\/reverse-and-forward-engineering-database-in-visual-studio-2010\/","title":{"rendered":"Reverse and forward engineering databases in Visual Studio 2010"},"content":{"rendered":"\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" align=\"right\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/visual-studio-2010-logo.png\" width=\"119\" height=\"92\" \/>In a <a href=\"https:\/\/ingmarverheij.com\/2012\/01\/reverse-and-forward-engineering-databases-in-visio-2010\/\">previous post<\/a> I\u2019ve described how you can reverse and forward engineer a database from a Microsoft SQL server to (and from Microsoft Office Visio 2010. But what if you\u2019re using Typed <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ss7fbaez.aspx\">Datasets<\/a> in Microsoft Visual Studio?<\/p>\n<p>Same as with Visio, reverse engineering an existing database from a SQL database is built-in and therefore fairly easy. So a best-practice is to design the database model in Visio, forward engineer it to a SQL database and import it in Visual Studio. <\/p>\n<p>If you want to forward engineer a <em>Microsoft ADO.NET compatible DataSet Schema File (XSD)<\/em> to a (Microsoft SQL) database you can use the <a href=\"https:\/\/xsd2db.sourceforge.net\/\">XSD2DB<\/a> tool created by <a href=\"https:\/\/weblog.smirnov.ca\/\">Alexsis Smirnov<\/a>.<\/p>\n<p>In this blog post I will demonstrate how to reverse engineer a database from Microsoft SQL server, and how to forward engineer a XSD back to a Microsoft SQL server.<\/p>\n<p><!--more--><\/p>\n<h2>How to reverse engineer a database from Microsoft SQL to Microsoft Visual Studio 2010<\/h2>\n<p>Start Microsoft Visual Studio 2010 and create a new project. For this example I&#8217;ll be using a Visual Basic Windows Forms Application, but the procedure is the same for other projects.<\/p>\n<p>&#160;<a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Start-Page-Microsoft-Visual-Studio-Administrator_2012-01-05_12-14-45.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Start-Page-Microsoft-Visual-Studio-Administrator_2012-01-05_12-14-45_thumb.png\" width=\"129\" height=\"74\" \/><\/a><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/New-Project_2012-01-05_12-16-42.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/New-Project_2012-01-05_12-16-42_thumb.png\" width=\"129\" height=\"90\" \/><\/a><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-17-12.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-17-12_thumb.png\" width=\"129\" height=\"74\" \/><\/a><\/p>\n<p>Rightclick on the project and add a new item (Ctrl+Shift+A). Search for \u2018DataSet\u2019 in the \u2018Search Installed Templates\u2019 on the right (name the dataset) and create the item.<\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Project-Add-New-Item.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Project-Add-New-Item_thumb.png\" width=\"129\" height=\"85\" \/><\/a><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Add-New-Item-WindowsApplication1_2012-01-05_12-21-20.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Add-New-Item-WindowsApplication1_2012-01-05_12-21-20_thumb.png\" width=\"129\" height=\"90\" \/><\/a><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-21-40.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-21-40_thumb.png\" width=\"129\" height=\"74\" \/><\/a><\/p>\n<p>Now expand the Server Explorer (if the Server is not visible, click on View &gt; Server Explorer), right click Data Connections and add a Data Connection. In the \u2018Add Connection\u2019 wizard specify the details of the connection like the server name (not localhost or 127.0.0.1), credentials and database name.<\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-23-13.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-23-13_thumb.png\" width=\"58\" height=\"92\" \/><\/a><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Server-Explorer-Data-Connections-Add-COnnection.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Server-Explorer-Data-Connections-Add-COnnection_thumb.png\" width=\"123\" height=\"92\" \/><\/a><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Add-Connection_2012-01-05_12-25-53.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Add-Connection_2012-01-05_12-25-53_thumb.png\" width=\"56\" height=\"92\" \/><\/a><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Microsoft-Visual-Studio_2012-01-05_12-26-02.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Microsoft-Visual-Studio_2012-01-05_12-26-02_thumb.png\" width=\"129\" height=\"88\" \/><\/a><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-26-13.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-26-13_thumb.png\" width=\"76\" height=\"92\" \/><\/a><\/p>\n<p>Now you have added the connection to the database you can expand the database and the objects you wish to reverse engineer in your DataSet Schema File. This can easily be done by dragging-and-dropping the objects on the \u2018DataSet Designer\u2019.<\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-29-44.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-29-44_thumb.png\" width=\"129\" height=\"74\" \/><\/a><\/p>\n<p>You now have successfully reverse engineered a SQL database to a DataSet Schema File in Microsoft Visual Studio 2010.<\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-30-23.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/WindowsApplication1-Microsoft-Visual-Studio-Administrator_2012-01-05_12-30-23_thumb.png\" width=\"502\" height=\"283\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p>&#160;<\/p>\n<h2>How to forward engineer a DataSet Schema File from Microsoft Visual Studio 2010 to Microsoft SQL<\/h2>\n<p><em>Please first download and extract the <a href=\"https:\/\/xsd2db.sourceforge.net\/\">XSD2DB<\/a> before proceeding..<\/em><\/p>\n<p>Open a command prompt and browse to the location where you\u2019ve extracted the XSD2DB tool. In my demo I\u2019ve extracted the files to C:\\Scripts\\XSD2DB.)<\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/CWindowssystem32cmd.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/CWindowssystem32cmd_thumb.png\" width=\"129\" height=\"79\" \/><\/a><\/p>\n<p>If you wish to save a DataSet Schema File (XSD) to a Microsoft SQL server you should specify the following command:<\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/CWindowssystem32cmd-2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/CWindowssystem32cmd-2_thumb.png\" width=\"129\" height=\"79\" \/><\/a><\/p>\n<p>Where <em>SQLServer<\/em> is the name of your SQL server, <em>NewDB <\/em>the name of the new database and <em>C:\\scripts\\DataSet1.xsd<\/em> the location of your DataSet Schema File (XSD).<\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/CWindowssystem32cmd-3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/CWindowssystem32cmd-3_thumb.png\" width=\"129\" height=\"85\" \/><\/a><\/p>\n<p>You now have successfully DataSet Schema File (XSD) to a Microsoft SQL server in Microsoft Visual Studio 2010.<\/p>\n<p>&#160;<a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Microsoft-SQL-Server-Management-Studio_2012-01-05_12-43-31.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/01\/Microsoft-SQL-Server-Management-Studio_2012-01-05_12-43-31_thumb.png\" width=\"305\" height=\"136\" \/><\/a><\/p>\n<h4><\/h4>\n<h4>&#160;<\/h4>\n<h4>REMARK<\/h4>\n<p>Even if the database does not yet exist use the \u2013f [force] parameter, otherwise it will fail.<\/p>\n<p>If you\u2019ll try to connect to 127.0.0.1 ,or did not enable remote login connections to the server, you\u2019ll probably get the following error.<\/p>\n<pre>System.Data.SqlClient.SqlException: Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.<\/pre>\n<p>More information about this error can be found <a href=\"https:\/\/blogs.msdn.com\/b\/sql_protocols\/archive\/2005\/09\/28\/474698.aspx\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a previous post I\u2019ve described how you can reverse and forward engineer a database from a Microsoft SQL server to (and from Microsoft Office Visio 2010. But what if you\u2019re using Typed Datasets in Microsoft Visual Studio? Same as with Visio, reverse engineering an existing database from a SQL database is built-in and therefore [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[392],"tags":[391,389,173,673,388],"class_list":["post-3243","post","type-post","status-publish","format-standard","hentry","category-visual-studio","tag-forward-engineering","tag-reverse-engineering","tag-sql","tag-visual-studio","tag-xsd"],"_links":{"self":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/3243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/comments?post=3243"}],"version-history":[{"count":4,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/3243\/revisions"}],"predecessor-version":[{"id":3247,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/3243\/revisions\/3247"}],"wp:attachment":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/media?parent=3243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/categories?post=3243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/tags?post=3243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}