最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

使用publishing转移MSSQL数据(2)[图]_MySQL

来源:懂视网 责编:小采 时间:2020-11-09 17:27:55
文档

使用publishing转移MSSQL数据(2)[图]_MySQL

使用publishing转移MSSQL数据(2)[图]_MySQL:接下来,用写字板打开,搜索数据库所有者都更改为dbo这样所有的账户都改为dbo,即可。下一步,把脚本命名为sqlscript.txt, 最好不要叫sqlscript.sql,下面会介绍。然后通过ftp把脚本放到网站的空间。编写脚本,例如命名为runsql.aspx ,然后运行
推荐度:
导读使用publishing转移MSSQL数据(2)[图]_MySQL:接下来,用写字板打开,搜索数据库所有者都更改为dbo这样所有的账户都改为dbo,即可。下一步,把脚本命名为sqlscript.txt, 最好不要叫sqlscript.sql,下面会介绍。然后通过ftp把脚本放到网站的空间。编写脚本,例如命名为runsql.aspx ,然后运行

接下来,用写字板打开,搜索数据库所有者都更改为dbo

这样所有的账户都改为dbo,即可。

下一步,把脚本命名为sqlscript.txt, 最好不要叫sqlscript.sql,下面会介绍。

然后通过ftp把脚本放到网站的空间。

编写脚本,例如命名为runsql.aspx ,然后运行该脚本即可还原数据库

<%

// Sample code for executing a T-SQL file using an ASP.NET page

// Copyright (C) Microsoft Corporation, 2007. All rights reserved.

// Written as a sample with use in conjuction with the SQL Server Database Publishing Wizard

// For more information visit http://www.codeplex.com/sqlhost/

// **************************************************************************

// Note: Please ensure that you delete this page once your database has been published to the remote server

// **************************************************************************

%>

<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Import Namespace="System.IO" %>

<%@ Import Namespace="System.Net" %>

<%

// **************************************************************************

// Update these variables here

// **************************************************************************

// Url of the T-SQL file you want to run

string fileUrl = @"http://www.sohu.com/sqlscript.txt";

// Connection string to the server you want to execute against

string connectionString = @"Data Source=11.1.1.1;

User ID=hdd;Password=dd;Initial Catalog=s603";

// Timeout of batches (in seconds)

int timeout = 20000;

%>

Executing T-SQL

<%

SqlConnection conn = null;

try

{

this.Response.Write(String.Format("Opening url {0}
", fileUrl));

// read file

WebRequest request = WebRequest.Create(fileUrl);

using (StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream()))

{

this.Response.Write("Connecting to SQL Server database...
");

// Create new connection to database

conn = new SqlConnection(connectionString);

conn.Open();

while (!sr.EndOfStream)

{

StringBuilder sb = new StringBuilder();

SqlCommand cmd = conn.CreateCommand();

while (!sr.EndOfStream)

{

string s = sr.ReadLine();

if (s != null && s.ToUpper().Trim().Equals("GO"))

{

break;

}

sb.AppendLine(s);

}

// Execute T-SQL against the target database

cmd.CommandText = sb.ToString();

cmd.CommandTimeout = timeout;

cmd.ExecuteNonQuery();

}

}

this.Response.Write("T-SQL file executed successfully");

}

catch (Exception ex)

{

this.Response.Write(String.Format("An error occured: {0}", ex.ToString()));

}

finally

{

// Close out the connection

//

if (conn != null)

{

try

{

conn.Close();

conn.Dispose();

}

catch (Exception e)

{

this.Response.Write(String.Format(@"Could not close the connection. Error was {0}", e.ToString()));

}

}

}

%>



需要注意

string fileUrl = @“http://www.sohu.com/sqlscript.txt”;

是用户脚本地址,因为很多空间禁止获取sql,所以,改成这样

string fileUrl = @“http://www.sohu.com/sqlscript.sql”;

系统可能无法运行。这样,就完成了数据库转移。

文档

使用publishing转移MSSQL数据(2)[图]_MySQL

使用publishing转移MSSQL数据(2)[图]_MySQL:接下来,用写字板打开,搜索数据库所有者都更改为dbo这样所有的账户都改为dbo,即可。下一步,把脚本命名为sqlscript.txt, 最好不要叫sqlscript.sql,下面会介绍。然后通过ftp把脚本放到网站的空间。编写脚本,例如命名为runsql.aspx ,然后运行
推荐度:
标签: 使用 数据 转移
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top