请问如何用vs2003做web安装项目,请详细些,本人新手,连发布也不会,谢谢。
另外,“msado20.tlb”无法排除,怎么办啊?
另外,“msado20.tlb”无法排除,怎么办啊?
解决方案 »
- winform程序怎么动态改窗口的标题
- c# 查找word中关键字并标红
- 获取XML根元素下的所有一级节点
- 想实现类似delphi中的包的功能,请给点思路.
- 求时间的计算问题!c#
- 将DataSet中的数据导入excel的问题(在线等,十万火急)
- C#调用windows api 给第三方软件界面传值
- SQL2005问题
- 字节数组转字符串
- 请问如何在得到一个数据库中有几个表,以及表名?在线等..............
- 使用vs2005的水晶报表,提示要注册,是否不注册,日后就不能使用了?
- A网站二进制序列化自定义的对象,存入sql数据库后,在B网站无法反序列化出来,如何解决?100分求救,急,在线等
http://www.cnblogs.com/xucanzhao/archive/2005/10/02/248063.html
安装部署打包类using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.IO;
using System.Data.SqlClient;
using System.Reflection;
namespace DBInstall
{
[RunInstaller(true)]
public partial class Installer2 : Installer
{
public Installer2()
{
InitializeComponent();
}
private System.ComponentModel.Container components = null;
//private string strPass = "";
private string server = "",user="",pwd="",dbname="";
Component Designer generated code
public override void Install(System.Collections.IDictionary stateSaver)
{
//入口
dbname= this.Context.Parameters["dbname"]; //dbname 为数据库名称
server = this.Context.Parameters["server"]; //server 为 服务器名称
user = this.Context.Parameters["user"]; //user 为 数据库登录名称
pwd = this.Context.Parameters["pwd"]; //pwd 为 数据库 登录密码
AddDBTable(dbname); //添加表,视图,存储过程
WriteWebConfig(); //更新webconfig 连接字符串
}
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;
}
}
/// <summary>
/// 执行sql 语句
/// </summary>
/// <param name="DatabaseName"></param>
/// <param name="Sql"></param>
private void ExecuteSql(string DatabaseName , string Sql)
{
string connString=string.Format("server={0};user id={1};password={2};database={3}",server,user,pwd,DatabaseName);
SqlConnection sqlConnection1 = new SqlConnection(connString) ;
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
{
}
}
/// <summary>
///数据库安装完成后更新webconfig 文件
/// </summary>
/// <returns></returns>
private bool WriteWebConfig()
{
System.IO.FileInfo FileInfo = new System.IO.FileInfo(this.Context.Parameters["targetdir"] + "/web.config");
if (!FileInfo.Exists)
{
throw new InstallException("Missing config file:" + this.Context.Parameters["targetdir"] + "/web.config");
}
System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
xmlDocument.Load(FileInfo.FullName);
bool FoundIt = false; //设置变量 初始值false 表示 更新不成功
foreach (System.Xml.XmlNode Node in xmlDocument["configuration"]["connectionStrings"])
{
if (Node.Name == "add")
{
if (Node.Attributes.GetNamedItem("name").Value == "sweaterConnectionString")
{
//Node.Attributes.GetNamedItem("value").Value = String.Format("Persist Security Info=False;Data Source={0};database={1};User ID={2};Password={3};Packet Size=4096;Pooling=true;Max Pool Size=100;Min Pool Size=1", ServerName, DBName, AdminName, AdminPwd);
Node.Attributes.GetNamedItem("connectionString").Value = string.Format("server={0};database={1};uid={2};password={3};Max Pool Size=512",server,dbname,user,pwd);
FoundIt = true;
}
}
}
if (!FoundIt)
{
throw new InstallException("Error when writing the config file: web.config");
}
xmlDocument.Save(FileInfo.FullName);
return FoundIt;
}
}
}