Build A C# SQL Server Database Export Utility

原创 2004年11月03日 08:39:00
One of the most common actions developers need to perform is the scripting of databases for archiving, distribution and installation purposes. Sql Server has the capability to script databases, but it is not complete. Scripting table data as insert statements is not offered, and because of this the process of scripting an entire database "in one shot" becomes quite cumbersome.

Not long ago, the nice people from Redmond put out a very useful ASP.NET web application entititled "Sql Web Data Administrator". Without spending a lot of time to explain, in case you haven't seen it, it is basically a web-based Enterprise Manager clone for SQL Server 2000 and MSDE databases.

Now one of the most interesting things you'll find with this, if you get far enough to start snooping around the generously - provided source code, is the fact that the web-based front end uses an assembly called "SQLAdmin.dll", which is essentially a managed code wrapper over the most important parts of the SQLDMO engine. Here's what the object hierarchy of SQLAdmin looks like:


As can be plainly seen, somebody spent a lot of very thoughtful time entity-izing all the SQLDMO database objects, thus making advanced managed - code SQL Server scripting and administration a breeze for anyone who is willing to take the time to use it.

To that end, I decided to put together a Windows Forms front end to enable easy database export scripting in a manner similar to the way the web-based app offers it, but without the dependency on having it installed as a web application. The UI to my creation looks like so:


When you TAB out of the Password field, it populates the list of Databases on the chosen server. At this point, one only needs to select a database, uncheck any of the Scripting options that aren't desired, and hit the EXPORT! button. A progress bar will increment while the scripting is being completed, and a Save File Dialog will come up, allowing you to save your SQL script wherever you want. Best of all, it will be a script for the ENTIRE DATABASE, INCLUDING TABLE DATA!

Here's what the main method looks like, under the hood:

I hope you enjoy the SQL DataBase Export Utility, and that it helps you to grow and think "outside the box". Full source code is available in the solution download below.

解决microsoft sql server error:15138的方法

When you drop a user in Microsoft SQL Server, an error occurs: 1. Drop failed for User fastnet(就是要删除...
  • gray13
  • gray13
  • 2009年08月18日 12:30
  • 7141

cron任务执行oracle冷备提示:Invalid format of Export utility name

使用oracle数据库用户建立数据库冷备脚本: ## 备份trade用户数据 ## 2016-02-05 11?00 /home/oracle/product/11gR2/bin/exp trade/...
  • kongkongtz
  • kongkongtz
  • 2016年02月05日 15:08
  • 1442

Msg 15138 The database principal owns a schema in the database, and cannot be dropped.

删除用户报错:   Msg 15138, Level16, State 1, Line 1 The database principal owns a schemain the database...
  • SmithLiu328
  • SmithLiu328
  • 2012年10月30日 15:50
  • 1791

2.1 使用Import and Export Wizard

和任何Microsoft产品一样,SQL Server附带了许多的向导来方便用户使用并减少产品开发周期以尽快面世。在本章中我们将学习用户可用的一些向导。这些向导使得转换数据以及部署程序包更为容易,而且...
  • Johnson_hejun
  • Johnson_hejun
  • 2008年11月19日 15:05
  • 3753

window2008 、 oracle11.2g 无法imp,dmp。

 现场环境:window2008 、 oracle11.2g  、客户端安装的是oracle10g一个简洁版 34M的。 在imp导入时,提示   Message 100 not foun...
  • High_Mount
  • High_Mount
  • 2015年01月15日 16:16
  • 2427

关于安装SQL2005后没有management sudio 或者是安装sql service database services失败的解决方案

为了做项目,需要安装SQL2005 , 我之前已经安装了SQL2008 并且有一款比较重要的软件需要依赖它,所以我就想在安装了SQL2008的情况下在安装一个SQL2005,结果第一次安装时下了个SQ...
  • A8572785
  • A8572785
  • 2012年07月03日 01:10
  • 5211


SQL SERVER DATABASE PROJECT能够从Visual Studio中创建的脚本来创建本地的数据库。比如说,别人给了你一个已经搭建好的Solution, 里边用到了SQL Serve...
  • sundacheng1989
  • sundacheng1989
  • 2014年03月26日 16:08
  • 3936

Sql server 日记 (Shipping log)

开发部今天说我们需要对一个数据库进行热备, 我问原因是什么,他们说原因是他们的一个测试数据库安装了其他的东西,造成服务器不稳定,最好能有个备份的数据库可以不在线但需要的时候可以用,(要求的安全性不是很...
  • liuhuayang
  • liuhuayang
  • 2010年08月12日 12:01
  • 680


  • yumushui
  • yumushui
  • 2014年08月04日 14:45
  • 398

SQL Server中,用Restore DataBase把数据库还原到指定的路径

restore database 数据库名 from disk='备份文件路径' with move '数据库文件名' to '数据库文件放置路径', move '日志文件名' to '日志文件存放...
  • u012138032
  • u012138032
  • 2017年07月05日 17:49
  • 1571
您举报文章:Build A C# SQL Server Database Export Utility