zoukankan      html  css  js  c++  java
  • sql server 2008数据库 降为 sql server 2005数据库 最终方案总结

    由于xx原因,sql server 要降级,所以有了下文。。。。

    一 直接 通过sql server 自带工具 生成脚本即可,具体操作方法如下:

    1.打开 Microsoft Sql Server Managenment Studio

    2.右键该数据库>>任务>>生成脚本

    3.按提示操作下一步,直到看到高级按钮,这时如下图操作

    如果生成的脚本文件不大,将生成的脚本直接在查询分析器 执行即可

    也可以尝试将每个对象生成一个文件后执行

    如果脚本文件较大则 需要 分割文件后执行

    如果单文件(整个库)执行过大的时候,可以尝试这样:

    1.先把每一类脚本文件分组后执行,如下图

    2.用以下程序逐个执行 xxtables xxviews xxfunctions  xxproc

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestSql.aspx.cs" Inherits="TestSql" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%@ Import Namespace="System.IO" %>
    <% string xx = "100";
    
    
       string[] filelist = Directory.GetFiles(Server.MapPath("~/website1/xxtables"));
       if (Request["dir"] != null) filelist = Directory.GetFiles(Server.MapPath("~/website1/"+Request["dir"].ToString()));
         foreach (string fileInfo in filelist)
         {
             List<string>errorList=new List<string>();
    
             //string fileName = "users.sql";
             //if (Request["sqlfile"] != null) fileName = Request["sqlfile"].ToString();
             //string strSql = System.IO.File.ReadAllText(Server.MapPath("~/website1/" + fileName + ""));
             ////Response.Write(strSql);
             /// 
             string strSql = System.IO.File.ReadAllText(fileInfo);
    
    
             string constr = "data source=.;uid=sa;pwd=1@1.com;database=21744new"; // 定义链接字符窜
    
             constr = "data source=localhost;uid=21744;pwd=123456789;database=21744"; //公网
    
             SqlConnection conn = new SqlConnection(constr);
             conn.Open();
    
             SqlCommand cmd = new SqlCommand();
             cmd.Connection = conn;
             //cmd.CommandText = strSql;            //为SqlCommand赋Sql语句;
             //cmd.ExecuteNonQuery();
             //conn.Close();
    
    
    
             //ArrayList Lists = Lj.ExecuteSqlFile(Server.MapPath("NetShop.sql")); //调用ExecuteSqlFile()方法,反回 ArrayList对象;
             String[] Lists = strSql.Split(new string[] {"
    GO
    "}, StringSplitOptions.RemoveEmptyEntries);
             string teststr = ""; //定义遍历ArrayList 的变量;
             string errorMsg = "";
             foreach (string varcommandText in Lists)
             {
                 try
                 {
                     teststr = varcommandText; //遍历并符值;
                     //Response.Write(teststr + "|@|<br>");
                     cmd.CommandText = teststr; //为SqlCommand赋Sql语句;
                     cmd.ExecuteNonQuery();
                 }
                 catch (Exception ex)
                 {
                     errorList.Add(ex.Message);
                     errorMsg += teststr + "<br/>";
                 }
                 //执行
             }
             conn.Close();
    
             Response.Write("执行完毕 ok啦,错误信息如下:errorMsg:" + errorList.Count.ToString()+">>"+fileInfo+"<br/>");
         }
    
    
    %>
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        </div>
        </form>
    </body>
    </html>

    当然如果客户端环境支持的话,也可以通过这种方式

    string[]filelist=Directory.GetFiles(Server.MapPath("~/xxtables"));
        foreach (string fileInfo in filelist)
        {
            
    
            string sqlConnectionString = "data source=.;uid=sa;pwd=1@1.com;database=21744new";
            //sqlConnectionString = "data source=localhost;uid=21744;pwd=123456789;database=21744";//公网
            FileInfo file = new FileInfo(fileInfo);
            string script = file.OpenText().ReadToEnd();
            SqlConnection conn = new SqlConnection(sqlConnectionString);
            Server server = new Server(new ServerConnection(conn));
            server.ConnectionContext.ExecuteNonQuery(script);
            Response.Write("完毕 OK");
            Response.Write(fileInfo+"<br/>");
            
        }

    如果单个文件还是比较大的话,那只能先单独生成架构脚本,再生成数据脚本了(对数据脚本 进行文件分割)

    下面是该例子完整源码

    http://www.haolizi.net/example/view_3253.html

  • 相关阅读:
    微信小程序HTTPS
    微信商城-1简介
    va_list
    Event log c++ sample.
    EVENT LOGGING
    Analyze Program Runtime Stack
    unknow table alarmtemp error when drop database (mysql)
    This application has request the Runtime to terminate it in an unusual way.
    How to check if Visual Studio 2005 SP1 is installed
    SetUnhandledExceptionFilter
  • 原文地址:https://www.cnblogs.com/duanweishi/p/4389439.html
Copyright © 2011-2022 走看看