在net中调用SQL语句,你可以用ado.net,但是它不支持数据库直接导出的格式,要转化一下,建议用批处理文件,然后用process来调用。把.NET程序部署到没有安装.NET Framwork的机器上 ?http://www.microsoft.com/China/Community/program/originalarticles/TechDoc/deployNETApp.mspx在微软官方网站下载Microsoft Visual Studio .NET 2003 引导程序插件
文件名叫:PluginInstaller.msi
下载地址:http://www.microsoft.com/downloads/details.aspx?FamilyID=627921a0-d9e7-43d6-a293-72f9c370bd19&displaylang=zh-cn
你安装了这个插件然后用IDE自带的安装部署即可,他会在你的安装包里另加三个文件:MDAC 2.8 和 .NetFramework 和中文语言包,并且自动判断系统是否已安装框架。
Microsoft Visual Studio .NET 2003制作安装程序 http://dev.csdn.net/article/28/article/27/27847.shtm部署ASP.NET的三大技术http://tech.ccidnet.com/pub/article/c295_a68309_p1.html在制作安装程序,不知如何才能将数据库结构及数据导入,高分求Duwamish7制作打包部署程序的源码及方法 http://community.csdn.net/Expert/topic/3368/3368253.xml?temp=.7017328项目打包时自定义安装属性,如数据库名等 http://blog.csdn.net/greystar/archive/2004/08/17/76716.aspx用Vs.net制作安装程序http://www.showyou.net/MyCode/ArticleView/Article_4641.html自动安装SQL Server数据库 http://www.cnblogs.com/wangsaokui/articles/9769.aspx安装程序时读取路径的问题 http://blog.joycode.com/fogshadow/archive/2004/04/30/20589.aspxasp.net打包的问题(1.修改文件夹访问权限;2.设置起始页) http://community.csdn.net/Expert/topic/3380/3380589.xml?temp=8.585757E-02NET平台下WEB应用程序的部署(安装数据库和自动配置)http://blog.csdn.net/lihonggen0/archive/2004/05/17/13654.aspx
把.NET程序部署到没有安装.NET Framwork的机器上
http://www.microsoft.com/China/Community/program/originalarticles/TechDoc/deployNETApp.mspx

解决方案 »

  1.   

    小示例:
    string file = dir + @"\database\Restore.bat";
    我是放在install项目中的文件夹中的,你可以用string file = @"c:\database\Restore.bat";等using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Configuration.Install;
    using System.IO;
    using System.Diagnostics;
    using System.Data;
    using System.Data.SqlClient;
    using System.Reflection;namespace PaladinWebInstall
    {
    /// <summary>
    /// PaladinInstaller 的摘要说明。
    /// </summary>
    [RunInstaller(true)]
    public class PaladinInstaller : System.Configuration.Install.Installer
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public PaladinInstaller()
    {
    // 该调用是设计器所必需的。
    InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化
    } /// <summary> 
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }
    #region 组件设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    }
    #endregion private void InstallDateBase() {// System.Reflection.Assembly  Asm;//          Asm= System.Reflection.Assembly.GetExecutingAssembly();//          System.IO.FileInfo FileInfo = new System.IO.FileInfo(Asm.Location);//          也可以得到当前安装的目录,如wwwroot目录下myweb\你的安装工程名.dll //创建数据库方法一
    //下面是进行数据库连线及命令
    // SqlConnection sqlConnection1 = new SqlConnection();
    // string DBName = this.Context.Parameters["DataBaseName"];
    // string DBServer = this.Context.Parameters["ServerName"];
    // string DBUser = this.Context.Parameters["InStallAdmin"];
    // string DBKey = this.Context.Parameters["InstallPassword"];
    // string dir=this.Context.Parameters["dir"];
    //
    // StreamWriter ss=new StreamWriter( @"c:\PaladinInstall.txt",true);
    // ss.WriteLine("data source=" + DBName + ";database=master;uid=" + DBUser +";password=" + DBKey);
    // ss.Close();
    // string CONSTR = "data source=" + DBServer +";database=master;uid=" + DBUser +";password=" + DBKey;
    // sqlConnection1.ConnectionString =  CONSTR; //数据库将安装到system32下
    // string CurDir = Directory.GetCurrentDirectory() + @"\TestData\database";
    // if(!Directory.Exists(CurDir))//不存在就新建一个
    // {
    // Directory.CreateDirectory(CurDir);
    // }
    //
    // string MSQL = "RESTORE DATABASE " + DBName +
    // " FROM DISK = '" + dir + @"database\database' " +
    // " WITH MOVE 'myDate_dat' TO '" + CurDir + @"\" + DBName + ".mdf', " +
    // " MOVE 'myDate_log' TO '" + CurDir + @"\" + DBName + ".ldf' " ;
    //
    // SqlCommand cmd = new SqlCommand(MSQL,sqlConnection1);
    // cmd.Connection.Open();
    // cmd.ExecuteNonQuery();
    // cmd.Connection.Close();
    //
    // if(sqlConnection1.State == ConnectionState.Open)
    // {
    // sqlConnection1.Close();
    // } //安装TreeView
    // ProcessStartInfo psi = new ProcessStartInfo();
    // psi.WorkingDirectory = dir+"\\database";
    // psi.FileName = dir + @"\database\iewebcontrols.msi ";
    // psi.UseShellExecute=true; //msi文件,如是exe不用设
    //
    // Process.Start(psi); //有哪位兄弟帮忙看一下。下面的代码。在执行时会说有一个进程在运行,导致安装这些控件时无法运行。
    //一定要关了。才可以.但是下面的代码比上面的代码有一点好处,下面的进程等到结束后继续整个install方法的其他代码。
    //而上面的代码,在实际运行时,整个安装已结束了。而安装TreeView的工作才刚开始。有点不同步 。
    //            Process myproc=new Process();
    //            myproc.EnableRaisingEvents=true;
    //       
    //            string file=dir + @"\database\iewebcontrols.msi";
    //       
    //            myproc.StartInfo.UseShellExecute=true;
    //            myproc.StartInfo.FileName = file;
    //            myproc.Start();
    //            myproc.WaitForExit();//此方法可以无限期等到进程运行完成,才执行下面的代码
    //            if(myproc.HasExited==true)
    //            {
    ////                    myproc.Kill();
    //            
    //            } //序列号验证
    // string diskNum= this.Context.Parameters["DiskNum"].ToString();
    // string serial= this.Context.Parameters["Serial"].ToString();
    // if(!this.IsValid(diskNum, serial))
    // {
    // string strHardNo = GetDiskNumber();
    // throw new InstallException("您提供的序列号不正确!");
    // } } public override void Install(System.Collections.IDictionary stateSaver) {
    try
    {
    base.Install(stateSaver);
    // this.InstallDateBase(); //调用上面的方法 ,创建数据库方法一 。
    AddDBTable(this.Context.Parameters["DataBaseName"]); //创建数据库方法二 。
    WriteLog( "Install" ) ;
    }
    catch
    {
    throw;
    }
    } public override void Uninstall(System.Collections.IDictionary stateSaver) {
    base.Uninstall(stateSaver);
    //UnInstallDataBase();
    DropDBTable( ) ;
    WriteLog( "Uninstall" ) ;
    } public override void Commit(System.Collections.IDictionary stateSaver) {
    base.Commit(stateSaver);
    WriteLog( "Commit" ) ;
    } public override void Rollback(System.Collections.IDictionary stateSaver) {
    base.Rollback(stateSaver);
    WriteLog( "Rollback" ) ;
    }
      

  2.   


    //==========================================================================================
    //                         创建数据库方法二
    //==========================================================================================
    // 添加 strDBName 数据库 。
    protected void AddDBTable(string strDBName) 

    try 

    ExecuteSql("master","CREATE DATABASE "+ strDBName); 
    // ExecuteSql(strDBName,"CREATE TABLE [dbo].[MK_Employees] ( [Name] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [Rsvp] [int] NULL , [Requests] [nvarchar] (4000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL  ) ON [PRIMARY]; CREATE TABLE [dbo].[PaladinVictory] ([id] [int] IDENTITY (1, 1) NOT NULL ,[username] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,[password] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ) ON [PRIMARY]; "); 
    // ExecuteSql(strDBName,GetSql("sql.txt")); 
    // 执行批处理文件
    string dir=this.Context.Parameters["dir"];
    string file = dir + @"\database\Restore.bat";
    System.Diagnostics.Process.Start( file) ;

    catch(Exception ex) 

    Console.Write("In exception handler :"+ex.Message); 
    WriteLog( "In exception handler :"+ex.Message ) ;

    }  // 添加 strDBName 数据库 。
    protected void DropDBTable( ) 

    try 

    // 执行批处理文件
    System.Diagnostics.Process.Start( @"c:\PaladinInstall\Dropdb.bat") ;

    catch(Exception ex) 

    Console.Write("In exception handler :"+ex.Message); 

    }  // 从文件获取 sql 语句
    private  string GetSql(string Name) //Name = sql.txt

    try 

    // Assembly Asm = Assembly.GetExecutingAssembly(); 
    // Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "."+Name); 
    // StreamReader reader = new StreamReader(strm); 
    // return reader.ReadToEnd(); // string file = @"c:\sql.txt" ;

    string dir=this.Context.Parameters["dir"];
    string file = dir + @"\database\sql.sql";
    StreamReader reader = new StreamReader(file); // string file1 = Asm.Location ;
    // string file2 = Asm.GetName().Name + "." + Name  ;
    // string file3 = this.Context.Parameters["dir1"] ;
    // string file4 = this.Context.Parameters["dir2"] ;
    // WriteLog( file +"          "+ file1 +"          "+ file2 +"        "+ file3 +"         "+ file4 ); return reader.ReadToEnd(); 

    catch (Exception ex) 

    Console.Write("In GetSql:"+ex.Message); 
    throw ex; 

    }  // 执行 sql 语句, DataBaseName 执行 sql  语句的当前数据库名称。
    private void ExecuteSql(string DataBaseName,string Sql) 

    SqlConnection sqlConnection1 = new SqlConnection();
    string DBName = this.Context.Parameters["DataBaseName"];
    string DBServer = this.Context.Parameters["ServerName"];
    string DBUser = this.Context.Parameters["InStallAdmin"];
    string DBKey = this.Context.Parameters["InstallPassword"];
    string dir=this.Context.Parameters["dir"];
    string CONSTR = "data source=" + DBServer +";database=master;uid=" + DBUser +";password=" + DBKey;
    sqlConnection1.ConnectionString =  CONSTR; System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand(Sql,sqlConnection1);  Command.Connection.Open(); 
    Command.Connection.ChangeDatabase(DataBaseName); 
    try 

    Command.ExecuteNonQuery(); 

    finally 

    Command.Connection.Close(); 

    } //==========================================================================================
    //                         其他操作
    //==========================================================================================
    private void WriteLog( string message ) 

    StreamWriter ss=new StreamWriter( @"c:\PaladinInstall.txt",true);
    ss.WriteLine( message );
    ss.Close();
    }
    }//class
    }
      

  3.   

    To happyjun2000:我安装了组件,但是制作的安装程序还是在提示缺少.net框架,点击“是”后,连接到WEB,点击“取消”后就退出安装程序,是不是却了一些设置的东东??
      

  4.   

    重起一下组件就可以了,非常感谢happyjun2000,准备接分了,祝早日升星!!