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
{
}
}
}
}
查看全文
相关阅读:
REDELK的安装和使用
Palo Alto GlobalProtect上的PreAuth RCE
渗透 Facebook 的思路与发现
抓取腾讯视频MP4文件
JS中整数的取整、取余、向上取整
centos7安装docker
业界难题-“跨库分页”的四种方案(转)
centos7设置时间
简单实现Shiro单点登录(自定义Token令牌)
nginx 反向代理时丢失端口的解决方案(转)
原文地址:https://www.cnblogs.com/ghd258/p/262046.html
最新文章
【工具】Sublime + MarkdownEditing + OmniMarkupPreviewer使用起来
【设计模式】简单工厂模式和工厂方法模式
【数据结构与算法】快速排序
【数据结构与算法】二分查找
【Kryo】简单地使用Kryo
【多线程】死锁与Java栈跟踪工具
【Linux】了解服务器的情况
【MySQL】MySQL表设计的常用数据类型
【MySQL】MySQL在CentOS的搭建
【ActiveMQ】Spring Jms集成ActiveMQ学习记录
热门文章
【工具】Windows7搭建FTP服务器
【Linux】Linux根目录下各文件夹的意义
【Web】Tomcat中利用Session识别用户的基本原理
【工具】我的Eclipse使用习惯
【运维】Java开发人员掌握的Linux命令
【计算机基础】对象的深拷贝和浅拷贝
【数据库】悲观锁与乐观锁与MySQL的MVCC实现简述
安恒Red Team 内部红蓝对抗框架
网络红军部队建设指南
实战攻防演习之红队
Copyright © 2011-2022 走看看