资源简介

asp.net c# 实现自动创建SqlServer数据库,提供给用户选择数据库名,登录名和密码

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.xml;

namespace CreatDatabase
{
    /// 
    /// yangyang8848
    /// 

    public partial class Form1 : Form
    {
        private DataTable servername = null;
        xmlDocument config = null;
        string serverName = null;
        string databaseName = null;
        string userName = null;
        string Password = null;
        string targetPath = null;
        public const string CONST_DATbase_PLACEHOLDER = “<se_NAME>>“;

        public Form1()
        {
            InitializeComponent();
            //加载xml文件
            System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(“CreatDatabase.Resources.InstallationFiles.xml“);
            config = new xmlDocument();
            //MessageBox.Show(“before load...“);
            config.Load(stream);
            //将网络上的SQL 服务器添加到列表框
            servername = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources();
            SetServer();
        }


        /// 
        /// 安装数据库
        /// 

        /// 
        private bool InstallDatabase()
        {
            string fileName = null;
            try
            {   
                ProcessStartInfo processInfo = new ProcessStartInfo(“osql.exe“);
                processInfo.Windowstyle = ProcessWindowstyle.Normal;

                //从资源中得到将要执行的SQL文件名称
                if (config != null)
                {
                    fileName = config.SelectSingleNode(“configroot/Files/Database/Add/File“).Attributes[“name“].Value;            
                }
                else
                {
                    MessageBox.Show(“文件未找到“);
                }

                //得到参数
                processInfo.Arguments = GetCommonProcessArguments(fileName “master“);

                EventLog.WriteEntry(“DatabaseInstaller“ processInfo.Arguments);
                PopulateDatabaseNamePlaceHolder(GetFullPath(fileName));
                Process osql = Process.Start(processInfo);
                //等待
                osql.WaitForExit();
                EventLog.WriteEntry(“DatabaseInstaller“ “Database created..“);
                osql.Dispose();
                return true;
            }
            catch (Exception ex)
            {
                //Customize if required.
                EventLog.WriteEntry(“DatabaseInstaller“ ex.Message EventLogEntryType.Error);
                MessageBox.Show(ex.Message);
                return false;
            }
        }

        private bool SetServer()
        {
            try
            {
                this.comboBox1.DataSource = GetServersName();
            }
            catch (Exception e)
 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3389  2006-08-29 13:42  CreatDatabase\CreatDatabase\CreatDatabase.csproj

     文件       6471  2006-08-29 14:23  CreatDatabase\CreatDatabase\Form1.cs

     文件       6020  2006-08-29 13:42  CreatDatabase\CreatDatabase\Form1.Designer.cs

     文件       5814  2006-08-29 13:42  CreatDatabase\CreatDatabase\Form1.resx

     文件        472  2006-08-29 13:27  CreatDatabase\CreatDatabase\Program.cs

     文件       1182  2006-08-29 13:27  CreatDatabase\CreatDatabase\Properties\AssemblyInfo.cs

     文件       2880  2006-08-29 13:27  CreatDatabase\CreatDatabase\Properties\Resources.Designer.cs

     文件       5612  2006-08-29 13:27  CreatDatabase\CreatDatabase\Properties\Resources.resx

     文件       1096  2006-08-29 13:27  CreatDatabase\CreatDatabase\Properties\Settings.Designer.cs

     文件        249  2006-08-29 13:27  CreatDatabase\CreatDatabase\Properties\Settings.settings

     目录          0  2006-08-29 13:27  CreatDatabase\CreatDatabase\Properties

     文件        193  2006-08-29 13:37  CreatDatabase\CreatDatabase\Resources\InstallationFiles.xml

     目录          0  2006-08-29 13:37  CreatDatabase\CreatDatabase\Resources

     文件        364  2006-08-29 13:37  CreatDatabase\CreatDatabase\scripts\Database.sql

     目录          0  2006-08-29 13:37  CreatDatabase\CreatDatabase\scripts

     目录          0  2006-08-29 14:24  CreatDatabase\CreatDatabase

     文件        928  2006-08-29 13:27  CreatDatabase\CreatDatabase.sln

    ..A..H.     18944  2006-08-29 14:24  CreatDatabase\CreatDatabase.suo

     目录          0  2006-08-29 13:27  CreatDatabase

     文件      24576  2006-08-29 14:23  CreatDatabase.exe

----------- ---------  ---------- -----  ----

                78190                    20


评论

共有 条评论