怎么实行ASP.NET部署连SQL数据库一起安装,C#语言,请教高手
怎么实行ASP.NET部署连SQL数据库一起安装,
C#语言,
请教高手
[解决办法]
http://www.google.com/search?hl=zh-CN&q=+ASP.NET%E9%83%A8%E7%BD%B2+SQL%E6%95%B0%E6%8D%AE%E5%BA%93&lr=
有很多文章
[解决办法]
http://hi.baidu.com/kuaihuowangzi/blog/item/6b75dbf29a697d13b07ec5cb.html
[解决办法]
要把SQL的数据库打包
[解决办法]
这个 总结的不错
http://blog.csdn.net/houlinghouling/category/129703.aspx
[解决办法]
方法很多
[解决办法]
可以使用InstallShield11.5,它自带了一个数据库导入功能,可以同时导入数据库中的记录。还可以创建Web站点,创建程序池等。
[解决办法]
mark
[解决办法]
using System.Reflection;
using System.Data;
using System.Data.SqlClient;
using System.IO;
安装数据库代码
/// <summary>
/// 获得配置文件中嵌入的文本文件
/// </summary>
/// <param name= "Name "> 文件名 </param>
/// <returns> </returns>
private string GetSql(string Name)
{
Assembly Asm = Assembly.GetExecutingAssembly();
Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + ". "+Name);
StreamReader reader = new StreamReader(strm);
return reader.ReadToEnd();
}
/// <summary>
/// 指定的数据库执行SQL语句
/// </summary>
/// <param name= "DatabaseName "> 数据库名 </param>
/// <param name= "sqlstring "> SQL语句 </param>
/// <returns> </returns>
private void ExecuteSql(string DataBaseName,string sqlstring)
{
System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand(sqlstring,sqlConn);
Command.Connection.Open();
Command.Connection.ChangeDatabase(DataBaseName);
try
{
Command.ExecuteNonQuery();
}
finally
{
Command.Connection.Close();
}
}
/// <summary>
/// 创建数据库及数据库表
/// </summary>
/// <param name= "DBName "> 数据库名 </param>
/// <param name= "assemblyName "> 配件中数据库脚本资源的名称 </param>
/// <returns> </returns>
protected bool CreateDBAndTable(string DBName)
{
bool Restult = false;
try
{
ExecuteSql( "master ", "CREATE DATABASE " + DBName);
ExecuteSql(DBName,GetSql( "bbssql.txt "));
Restult = true;
}
catch(Exception ex)
{
//次段代码为调试用可以不添加
StreamWriter sw = new StreamWriter(@ "c:\SrInforSys.txt ");
sw.WriteLine( "[SrInforSys案装错误] ");
sw.WriteLine(ex.Message.ToString());
sw.Close();
}
return Restult;
}
/// <summary>
/// 安装数据库
/// </summary>
/// <param name= "stateSaver "> </param>
public override void Install(IDictionary stateSaver)
{
base.Install (stateSaver);
if(!CreateDBAndTable(this.Context.Parameters[ "dbname1 "].ToString()))
throw new ApplicationException( "创建数据库时出现严重错误! ");
}