Use a database template to create a conveniently deployed. Net project debugging environment

Source: Internet
Author: User
Tags sql server query
This document uses petshop as an example to describe how to use visutal studio. the database template in. Net puts the database design of the project into the solution of the project, and uses this method to quickly port the database of the entire petshop project from SQL Server to MSDE. Note: This article does not discuss petshop technology any more. It just uses its database as a general demonstration. Source code of the petshop online pet store example is: http://www.gotdotnet.com/team/compare. Introduction: SQL Server facilitates powerful queries and management tools make it our development. NET database applications, even if you are not developing SQL Server-based applications, you will also like to use its unique powerful query analyzer to help you complete the project. However, it is inconvenient to use SQL Server to develop project applications, that is, when half of the projects need to be transferred to another machine, if you are not familiar with SQL Server, you will find that you are almost helpless, because SQL server does not put the entire database in a file like access, you can easily package it in your project folder. You may say that you can use the SQL Server Enterprise Manager to generate creation scripts and then export and back up data. Although this is feasible, it is always inconvenient. By using the database template project, you can put your database table creation scripts, data files, and stored procedures together with your project. In this way, it is easy to re-build the database environment required by the debugging program anywhere, and it can be stored in your Visual Studio.. Net integration debugging environment directly modify scripts and stored procedures. The following describes in detail how to add a database template project for petshop, and export the creation script, data file, and stored procedure of the petshop database to the template and package it together with the project, and then export it to the MSDE desktop data engine. Create a database template project: first, we need to have an installed petshop project (for specific installation instructions and steps, see the instructions of petshop), and then in Visual Studio. open its project file, select "New Project" in the "file" menu, and select "database project" for "Other Projects" in the dialog box ", in the template list on the right, select "database project" and "add solution". The name and path are shown in. Click OK. In the data connection dialog box, select petshop database: after confirming, in the solution, we can see the newly created database template project for petshop, as shown in: generate the creation script and stored procedure: select the server resource manager on the left, right-click the data connection of petshop and choose "generate creation script", as shown in: select all tables and all stored procedures in the following dialog box: save the path and select "create scripts" in the database template project: If there are no exceptions, you have generated many SQL scripts in create scripts. File. Then, press the Shift key in the data connection to select all the tables at a time, right-click and select "export data": the data is also placed under "create scripts. Generate command file: select the database template project in the project manager, and then select generate command file in "project" in the main menu, as shown in: to export data, select the "add data" button in the lower-right corner to select the tables to export data. Click OK. A command file named petshopdb. CMD is generated in the project. Here, we have created a complete petshop database template project, and can easily edit and modify the script in Visual Studio. NET. Next, we will import the data to the MSDE desktop database, and then change the petshop database to MSDE to simulate the database migration process. Port the database to MSDE: first, use the SQL Server Query analyzer or the enterprise manager to create a database named petshop in MSDE, In the generated petshopdb. right-click on CMD and choose "run". In the displayed dialog box, enter the server and petshop database of MSDE. Click "OK". Then, we can see the database creation and data replication processes: finally, open the petshop database in MSDE to view all the data tables, stored procedures, and complete data. Now let's test the results and see if our petshop has been transplanted to MSDE from SQL Server. Let's modify the petshop web. shows the data connection string in the config file:

Save and run the program. Oh, we saw the familiar big parrot again. Although they were installed on MSDE this time, they still looked so cute. & #61514; Conclusion: using the database template project, you can separate your database design and data from the database and store them in your project file, simplify the database transfer and distribution process to facilitate the rapid migration and deployment of your application projects.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.