zoukankan
html css js c++ java
安装程序自动安装数据库
添加新项中添加安装程序类
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Configuration.Install;
using
System.IO;
using
System.Data.SqlClient;
using
System.Reflection;
namespace
DBCustomAction
{
/**/
///
<summary>
///
DBCustomAction 的摘要说明。
///
</summary>
[RunInstaller(
true
)]
public
class
DBCustomAction : System.Configuration.Install.Installer
{
/**/
///
<summary>
///
必需的设计器变量。
///
</summary>
private
System.ComponentModel.Container components
=
null
;
private
string
strPass
=
""
;
public
DBCustomAction()
{
//
该调用是设计器所必需的。
InitializeComponent();
//
TODO: 在 InitComponent 调用后添加任何初始化
}
Component Designer generated code
#region
Component Designer generated code
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
}
#endregion
public
override
void
Install(System.Collections.IDictionary stateSaver)
{
//
入口
strPass
=
this
.Context.Parameters[
"
strPass
"
];
AddDBTable(
"
RequestSys
"
);
//
RequestSys为数据库名称
}
private
string
GetSql(
string
strName)
{
try
{
//
' Get the current assembly.
Assembly Asm
=
Assembly.GetExecutingAssembly();
//
Resources are named using a fully qualified name
Stream strm
=
Asm.GetManifestResourceStream(Asm.GetName().Name
+
"
.
"
+
strName);
//
Read the contents of the embedded file.
StreamReader reader
=
new
StreamReader(strm);
//
,System.Text.Encoding.Unicode);
return
reader.ReadToEnd();
}
catch
{
return
null
;
}
}
private
void
ExecuteSql(
string
DatabaseName ,
string
Sql)
{
SqlConnection sqlConnection1
=
new
SqlConnection(
"
user id=sa;password=
"
+
strPass
+
"
;database=master;server=(local)
"
) ;
SqlCommand Command
=
new
SqlCommand(Sql, sqlConnection1);
Command.Connection.Open();
Command.Connection.ChangeDatabase(DatabaseName);
try
{
Command.ExecuteNonQuery();
}
finally
{
//
Finally, blocks are a great way to ensure that the connection
Command.Connection.Close();
}
}
protected
void
AddDBTable(
string
strDBName )
{
try
{
//
Create the database.
ExecuteSql(
"
master
"
,
"
CREATE DATABASE
"
+
strDBName);
//
Create the tables.
ExecuteSql(strDBName, GetSql(
"
sql.txt
"
));
}
catch
{
}
}
}
}
查看全文
相关阅读:
LOJ 6192 城市网络(树上倍增)
SDOI2010代码拍卖会 (计数类DP)
失控的未来交通工具 (LOJ 508,带权并查集,数论)
线段树维护区间前k小
POJ 1966 Cable TV Network (最大流最小割)
网络流学习笔记
最大子矩阵和
POJ 1723 Soldiers (中位数)
最大子矩阵求法详解
CH0805 防线 (二分值域,前缀和,特殊性质)
原文地址:https://www.cnblogs.com/ghd258/p/262046.html
最新文章
【LOJ #3144】「APIO 2019」奇怪装置
AtCoder Beginner Contest 133
C++中的swap(交换函数)
oj上的测试点信息
利用sort对结构体进行排序
java中如何测试一段代码的运行时间
刽子手游戏
set和muliset
快速排序
C++中如何记录程序运行时间
热门文章
Codeblocks中文乱码解决方法。
11月3日考试题解
YNOI2016:掉进兔子洞 (莫队+bitset)
洛谷 P4902 乘积 (约数筛,前缀和(积))
浅析拯救小矮人的 nlogn 算法及其证明
LOJ bitset+分块 大内存毒瘤题
LOJ 6060「2017 山东一轮集训 Day1 / SDWC2018 Day1」Set(线性基,贪心)
【ARC101F】Robots and Exits 树状数组优化DP
洛谷 P4665 [BalticOI 2015]Network
CF261E Maxim and Calculator (质数,完全背包)
Copyright © 2011-2022 走看看