自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

快速將網(wǎng)站的Mssql數(shù)據(jù)庫遷移國外

數(shù)據(jù)庫
將網(wǎng)站的Mssql數(shù)據(jù)庫遷移國外是一種很高科技的技術(shù),含金量是相當(dāng)高的,本文就為大家介紹快速將網(wǎng)站的Mssql數(shù)據(jù)庫遷移國外的方法。

導(dǎo)讀:將網(wǎng)站從國內(nèi)網(wǎng)站搬移到了Lunarpage,程序轉(zhuǎn)移比較簡單,使用cuteftp上傳上去就可以了。但是數(shù)據(jù)庫轉(zhuǎn)移一直都是很棘手的一個(gè)問題。數(shù)據(jù)庫轉(zhuǎn)移最簡單的方法是使用DTS,但是Lunarpages數(shù)據(jù)庫不支持遠(yuǎn)程數(shù)據(jù)庫鏈接,所以無法使用DTS,因此只好使用publishing轉(zhuǎn)移數(shù)據(jù)。

具體步驟如下:

Step1. 運(yùn)行 SqlPubWiz.exe

Publishing類似MS SQL的一個(gè)插件,你可以到

http://www.microsoft.com/downloads/details.aspx?FamilyId=56E5B1C5-BF17-42E0-A410-371A838E570A

下載,運(yùn)行后可以在tools下找到

 

Step2 運(yùn)行后,會(huì)出現(xiàn)運(yùn)行向?qū)?,找到本地?cái)?shù)據(jù)庫

 

Step3.選項(xiàng)要生成的類型,系統(tǒng)會(huì)自動(dòng)檢測可用內(nèi)容,一般之選擇“表”“存儲(chǔ)過程”和“視圖”,對(duì)于Users就不要讓系統(tǒng)生成了

 

點(diǎn)擊Next,一直完成。

更改數(shù)據(jù)庫擁有者

以下是核心,非常重要,否則不會(huì)成功。

在我們使用網(wǎng)站時(shí),通常會(huì)使用SP給我們的賬戶,例如我原來的數(shù)據(jù)庫叫做 “bf4190_”

當(dāng)時(shí)網(wǎng)站供應(yīng)商給我的賬戶為 bf419,則系統(tǒng)生成的數(shù)據(jù)表如下

 

你可以看到,有的表前面有前綴bf419,有的有前綴dbo (db哦,是database owner),這很不同。因?yàn)樵谖覀兘⒈頃r(shí),腳本的寫法略有區(qū)別。

寫法一:

CREATE TABLE [dbo].[ads] (

[id] [int] IDENTITY(1,1) NOT NULL,

[name] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

[img] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

}
 

寫法二:

CREATE TABLE [ads] (

[id] [int] IDENTITY(1,1) NOT NULL,

[name] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

[img] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

 

}
 


對(duì)于第一種,生成的表就是 dbo.ads, 而第二個(gè)表則是 bf419.ads,因?yàn)槟愕腷f419其實(shí)就是dbo,所以系統(tǒng)可以運(yùn)行。

但是,當(dāng)你把數(shù)據(jù)庫轉(zhuǎn)移到新的服務(wù)商時(shí),如果你的賬戶叫做XXXX,則上面建立bf419.ads則出現(xiàn)錯(cuò)誤,而用 dbo.ads 則完全沒有問題。

通常新舊服務(wù)商給用戶開的用戶名并不一樣,所以我們需要更改一下數(shù)據(jù)庫的所有者。

#p#

接下來,用寫字板打開,搜索數(shù)據(jù)庫所有者都更改為dbo

 

這樣所有的賬戶都改為dbo,即可。

下一步,把腳本命名為sqlscript.txt, 最好不要叫sqlscript.sql,下面會(huì)介紹。

然后通過ftp把腳本放到網(wǎng)站的空間。

編寫腳本,例如命名為runsql.aspx ,然后運(yùn)行該腳本即可還原數(shù)據(jù)庫

<%

// 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;

 

 

%>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Executing T-SQL</title>

</head>

<body>

<form id="form1" runat="server">

<div>

 

</div>

</form>

<%

SqlConnection conn = null;

try

{

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

 

// read file

WebRequest request = WebRequest.Create(fileUrl);

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

{

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

 

// 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()));

}

}

}

 

 

%>

</body>

</html>
 

需要注意:

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

是用戶腳本地址,因?yàn)楹芏嗫臻g禁止獲取sql,所以,改成這樣

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

系統(tǒng)可能無法運(yùn)行。到這,數(shù)據(jù)庫遷移的工作就全部完成啦。希望上文中講到的內(nèi)容對(duì)大家能夠有所幫助。

【編輯推薦】

  1. MySQL數(shù)據(jù)庫中數(shù)據(jù)被刪除后的恢復(fù)
  2. 網(wǎng)店與商城要重視數(shù)據(jù)庫營銷
  3. SQL Server數(shù)據(jù)庫服務(wù)器高性能設(shè)置
責(zé)任編輯:迎迎 來源: 博客網(wǎng)
相關(guān)推薦

2023-05-10 09:24:10

TypeScript工具

2010-09-30 09:11:01

2011-03-14 13:43:56

2010-05-21 17:51:58

MySQL數(shù)據(jù)庫

2012-10-19 10:21:07

數(shù)據(jù)庫負(fù)載均衡mssqlserver

2011-05-11 10:26:36

MySQL數(shù)據(jù)庫無縫遷移

2011-09-23 09:09:38

數(shù)據(jù)庫遷移

2020-08-13 07:42:15

數(shù)據(jù)庫Flyway代碼

2010-06-04 18:32:48

MySQL數(shù)據(jù)庫

2011-07-14 15:24:26

MSSQL數(shù)據(jù)庫跨數(shù)據(jù)庫查詢

2010-06-01 17:45:57

MySQL數(shù)據(jù)庫

2023-12-21 09:16:40

Electron前端多進(jìn)程架構(gòu)

2010-05-28 13:21:48

MySQL數(shù)據(jù)庫

2010-05-28 11:05:40

MSSQL Serve

2009-03-19 09:44:07

SQL Server數(shù)據(jù)庫遷移數(shù)據(jù)庫

2019-08-13 15:52:34

數(shù)據(jù)庫同步遷移

2011-04-29 14:30:23

2017-06-22 16:00:07

數(shù)據(jù)庫NoSQL遷移實(shí)踐

2011-10-14 13:50:54

數(shù)據(jù)庫遷移

2017-11-22 09:20:41

數(shù)據(jù)庫在線數(shù)據(jù)遷移Subscriptio
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)