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
{
}
}
}
}
查看全文
相关阅读:
驱动编程杂谈
mysql数据库之视图
mysql编程
添加内核编译选项
内核编译遇到的一些问题
jffs2和yaffs2文件系统
宿主机挂载和使用嵌入式文件系统
只读文件系统
Makefile的简单编写
UITableview delegate dataSource调用探究
原文地址:https://www.cnblogs.com/ghd258/p/262046.html
最新文章
PySide2兼容PySide1的补丁代码
数字色彩的艺术 | The Art Of Digital Color(修订)
闲话ACES(修订)
从列向量、线性组合到矩阵
Schema、API Schema与MFn
为毛GPU Cache不能移动顶点?
简易Asset工作流
闲话Pipeline In Maya
代理设计模式在auto_ptr及smart_ptr中的体现
USD词汇表(USD Glossary)
热门文章
USD在CentOS7.0操作系统下的安装方法
Skin Microstructure Deformation with Displacement Map Convolution项目小结
Qt控制流简析
hiero.ui获取实例名的方法
浏览器的多线程机制(转)
Assets Library开发总结
django中form页面刷新后自动提交的解决方案
一些关于three.js的摘抄笔记
关于Asset Library核心功能的一些计划
字符设备驱动编程(一)
Copyright © 2011-2022 走看看