我把数据库文件mydata.sql也发送安装的应用文件夹中,但在安装的过程中出现找不到文件?
我也做了个安装类, public InstallerMySample()
{
InitializeComponent();
}
public override void Install(System.Collections.IDictionary stateSaver)
{
//数据库安装程序入口
_saPassword = this.Context.Parameters["pwd"];
_dataBaseName = this.Context.Parameters["dbname"];
_targetPath = this.Context.Parameters["targetdir"];
_servername = this.Context.Parameters["server"];
_username = this.Context.Parameters["user"]; iis = this.Context.Parameters["iis"];
port = this.Context.Parameters["port"];
//添加数据库
AddDBTable();
.......
private void ExcuteScript()
{
try
{
Process sqlProcess = new Process();
//调用osql必须在目标机,也就是安装的机子上要有安装SQLServer服务器
//不然找不到这个命令
sqlProcess.StartInfo.FileName = "osql.exe";
//如下所指的SQL脚本文件是打包打安装项目的文件名,
//targetPath就是在安装界面用户指定的安装目录
sqlProcess.StartInfo.Arguments = string.Format("-U {0} -P{1} -d {2} -S {3} -i {4}mydata.sql",
_username, _saPassword, _dataBaseName, _servername, _targetPath); sqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
sqlProcess.Start();
sqlProcess.WaitForExit();
sqlProcess.Close();
}
catch (Exception ex)
{
throw ex;
}
}
我也做了个安装类, public InstallerMySample()
{
InitializeComponent();
}
public override void Install(System.Collections.IDictionary stateSaver)
{
//数据库安装程序入口
_saPassword = this.Context.Parameters["pwd"];
_dataBaseName = this.Context.Parameters["dbname"];
_targetPath = this.Context.Parameters["targetdir"];
_servername = this.Context.Parameters["server"];
_username = this.Context.Parameters["user"]; iis = this.Context.Parameters["iis"];
port = this.Context.Parameters["port"];
//添加数据库
AddDBTable();
.......
private void ExcuteScript()
{
try
{
Process sqlProcess = new Process();
//调用osql必须在目标机,也就是安装的机子上要有安装SQLServer服务器
//不然找不到这个命令
sqlProcess.StartInfo.FileName = "osql.exe";
//如下所指的SQL脚本文件是打包打安装项目的文件名,
//targetPath就是在安装界面用户指定的安装目录
sqlProcess.StartInfo.Arguments = string.Format("-U {0} -P{1} -d {2} -S {3} -i {4}mydata.sql",
_username, _saPassword, _dataBaseName, _servername, _targetPath); sqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
sqlProcess.Start();
sqlProcess.WaitForExit();
sqlProcess.Close();
}
catch (Exception ex)
{
throw ex;
}
}
解决方案 »
- C# 视屏绑定
- 一道算法题,自己想出来的,求答案!
- 无法打印的问题。
- 問個簡單問題
- 类中的结构体集合无法赋值的问题
- 如何让查询结果显示在另一窗体的Datagridview中
- visual studio 2005 -> 新建项目 -> visual c#,里面只有4个选项,window、智能设备、数据库、初学者工具包、没有web!
- asp.net(C#)数据库连接问题
- Microsoft.CSharp.Compiler.Compile的问题
- 帮忙:解决一下计算字段问题
- skinEngine皮肤控件问题
- c# treeview 选中某项后,焦点移开后,比如焦点到文本框里了,此时发现treeview刚才选中的某项的选中状态消失了。
{
SqlConnection mySqlConnection=new SqlConnection(conn);
SqlCommand Command=new SqlCommand(Sql, mySqlConnection);
mySqlConnection.Open();
mySqlConnection.ChangeDatabase(DatabaseName);
try
{
Command.ExecuteNonQuery();
}
finally
{
mySqlConnection.Close();
}
}
string connstr = String.Format("data source={0};user id={1};password={2};persist security info=false;packet size=4096", Context.Parameters["server"],Context.Parameters["user"], Context.Parameters["pwd"]);
ExecuteSql(connstr, "master", "CREATE DATABASE " +Context.Parameters["dbname"]);
Process sqlprocess=new System.Diagnostics.Process();
sqlprocess.StartInfo.FileName = "osql.exe ";
sqlprocess.StartInfo.Arguments = String.Format(" -U {0} -P {1} -d {2} -i {3}db.sql", Context.Parameters["user"], Context.Parameters["pwd"],Context.Parameters["dbname"],Context.Parameters["targetdir"]);
sqlprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
sqlprocess.Start();
sqlprocess.WaitForExit();
sqlprocess.Close();
参考
参考
code:
protected void AddDBTable(string strDBName)
{ try
{ //Create the database. ExecuteSql("master", "CREATE DATABASE " + strDBName); // Create the tables. ExecuteSql(strDBName, GetSql("mydata.sql")); // ExecuteSql(strDBName, GetSql("Fuction.sql")); // ExecuteSql(strDBName, GetSql("View.sql")); } catch (Exception ex)
{ throw ex; } }
private string GetSql(string strName)
{ try
{ Assembly Asm = Assembly.GetExecutingAssembly(); Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + strName); StreamReader reader = new StreamReader(strm); return reader.ReadToEnd(); } catch (Exception ex)
{ throw ex; } }
protected void Page_Load(object sender, EventArgs e)
{
Assembly Asm = Assembly.GetExecutingAssembly(); Response.Write(Asm.GetName().Name + "." + "strName");
}
得到结果:App_Web_9jyxd8us.strName
这是什么原因?