Table of Contents
不通过使用管理工具把SQL数据库部署到远程SQL服务器的步骤
Home Database Mysql Tutorial 技巧和诀窍: 如何上传一个.SQL文件到远程主机并且执行它来部署

技巧和诀窍: 如何上传一个.SQL文件到远程主机并且执行它来部署

Jun 07, 2016 pm 03:23 PM
upload Host how Skill document Remotely

Tip/Trick: How to upload a .SQL file to a Hoster and Execute it to Deploy a SQL Database 【原文发表日期】 Thursday, January 11, 2007 12:20 AM 上个月 (英文),我讨论了新的(免费的)数据库发布向导,它是设计来充分简化在web主机环境中上传和部署 SQ

Tip/Trick: How to upload a .SQL file to a Hoster and Execute it to Deploy a SQL Database
【原文发表日期】 Thursday, January 11, 2007 12:20 AM

上个月 (英文),我讨论了新的(免费的)数据库发布向导,它是设计来充分简化在web主机环境中上传和部署 SQL Express 和 SQL Server数据库的。

在 第一个关于数据库发布的贴子 (英文)里 ,我示范了你如何可以使用数据库发布向导自动生成 .SQL 安装文件,该文件中将包含重建你的数据库数据定义(表,视图,存储过程,触发器,全文索引目录等等)以及以你原来数据库中同样的数据填充新数据库所需的脚本。这提供了一个极其容易的方法来构造在另外一个服务器上完全复制你的数据库的 .SQL 脚本:

技巧和诀窍: 如何上传一个.SQL文件到远程主机并且执行它来部署

在我以前的帖子里,我提到主机供应商经常提供在线SQL管理工具,你可以用它来打开/运行你新生成的 .SQL 文件,或者会提供SQL查询工具允许你拷贝/粘贴 .SQL 文件的内容到一个查询执行窗口来运行这些SQL语句。但不幸的是,并不是所有的主机供应商支持类似的工具。即使在那些支持类似工具的主机供应商那里,你也会遇上一些情形,譬如你生成的 .SQL 文件是如此之大,把它拷贝/粘贴进一个文本框是行不通的(提交一个 200M 字节内容的表单一般都会造成超时)。

这个帖子示范了把 .SQL 文件部署到远程主机环境中去的另外一个方法,这个方法不要求你的主机供应商在后端为你配置和安装任何东西。

不通过使用管理工具把SQL数据库部署到远程SQL服务器的步骤

下面是把一个本地数据库不通过使用任何管理工具就部署到远程主机上去的步骤:

第一步:生成一个包含数据定义和数据的 .SQL文件

远程部署数据库到主机环境的第一步是生成一个 .SQL 文件,内含你数据库的数据定义和数据。按我的 第一个关于数据库发布的博客帖子 (英文)里的步骤,来了解如何为 SQL Express 或 SQL Server数据库生成一个 .SQL 文件。

第二步: 把 .SQL 文件FTP到你的远程主机上去

生成 .SQL 文件之后,使用FTP或者其他文件传输机制将它上传到你的远程主机上去。最好是把这个文件拷贝到一个远程用户不易访问的受保护的场所。一个建议,给这个文件一个随机的名字,然后将它上传到 /app_data 文件夹,因为在默认情形下,该文件里的内容是受保护的。

用FTP来上传这个文件的好处是,它不会强迫你限制 .SQL 文件的大小。有必要的话,该文件的大小可达几百个M字节之多。

第三步: 下载 RunSQL.aspx 辅助页面

访问这个页面,下载其上连接的 RunSQL.aspx 文件。

RunSQL.aspx文件是个ASP.NET页面,是SQL Server产品组编写的,支持2个参数: 1) .SQL 文件的名字, 以及 2) 数据库的连接字符串。运行RunSQL.aspx页面,它会打开指定的 .SQL 文件,在通过连接字符串指定的数据库中迭代执行文件中的每一句SQL语句。这就会把 .SQL 文件中定义的数据库配备到远程的目标数据库中去。

第四步: 编辑 RunSQL.aspx 辅助页面

在本地打开/编辑RunSQL.aspx文件,设置好你的 .SQL 文件名字,以及提供与你的主机供应商给予你的SQL数据库对应的连接字符串:

技巧和诀窍: 如何上传一个.SQL文件到远程主机并且执行它来部署

把 > 标记以及相关的连接字符串标记替换成你主机环境中的正确配置值。注意,除非你知道你的 .SQL 文件的完整路径,你大概需要使用ASP.NET中的Server.MapPath(fileName)方法来推算出你应用中与 .SQL 文件的相对路径相对应的绝对路径。譬如:

 

    // Filename of the T-SQL file you want to run
    
string fileName Server.MapPath("personal.SQL");    
    
    
// Connection string to the server you want to execute against
    
string connectionString @"Server=server123;User ID=user123;Password=password123;Initial Catalog=MyDBName123";  
    
    
// Timeout of batches (in seconds)
    
int timeout 600;

 

第五步: 把 RunSQL.aspx 辅助页面上传到你的远程主机

完成更改文件名和连接字符串值之后,把RunSQL.aspx文件上传到你的远程主机上去(譬如,使用FTP)。

为安全的原因,我建议你在上传时给该文件一个随机的文件名,这样,别人就不容易找到这个文件并执行它了。

第六步: 用浏览器访问 RunSQL.aspx 辅助页面

上传后,通过浏览器访问远程的RunSQL.aspx网页,这会导致你远程服务器上的网页分析 .SQL 文件,执行其中的所有SQL语句。 因为 .SQL 文件包含了重建数据库所需的数据库数据定义和数据填充的所有语句,网页执行完毕后,你就将一个一模一样的数据库部署到你的远程主机上了:

技巧和诀窍: 如何上传一个.SQL文件到远程主机并且执行它来部署

第七步: 删除 RunSQL.aspx 和 .SQL 文件

运行完你的 .SQL 脚本之后,把RunSQL.aspx网页和 .SQL 文件同时从你的远程主机服务器上删除。

为安全的原因,你想要任何其他人能够远程访问RunSQL.aspx网页,因为它也许会重建你的数据库,导致数据丢失。

第八步: 更新你应用的Web.Config文件来指向主机环境中的数据库

剩下的最后一步是更新你的web.config文件的 部分指向你的远程主机数据库的连接字符串值。之后,你的应用就应该在远程主机上正常工作了。

希望本文对你有所帮助,

Scott

附注:要阅读我写的其他的技巧,诀窍和Recipes帖子的话,请访问这个网页。

 

ASP.NET, .NET, Data, SQL Server, Tips and Tricks

 
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. Mar 21, 2024 pm 09:17 PM

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box "Error 0x80004005: Unspecified Error" will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

Win11 Tips Sharing: Skip Microsoft Account Login with One Trick Win11 Tips Sharing: Skip Microsoft Account Login with One Trick Mar 27, 2024 pm 02:57 PM

Win11 Tips Sharing: One trick to skip Microsoft account login Windows 11 is the latest operating system launched by Microsoft, with a new design style and many practical functions. However, for some users, having to log in to their Microsoft account every time they boot up the system can be a bit annoying. If you are one of them, you might as well try the following tips, which will allow you to skip logging in with a Microsoft account and enter the desktop interface directly. First, we need to create a local account in the system to log in instead of a Microsoft account. The advantage of doing this is

Lenovo YOGA Portal mini host officially announced on July 27, released by ChinaJoy, with built-in 350W power supply Lenovo YOGA Portal mini host officially announced on July 27, released by ChinaJoy, with built-in 350W power supply Jul 23, 2024 pm 01:47 PM

According to news from this site on July 23, Lenovo’s YOGA Portal high-performance desktop computer, which has been exposed for a long time, is now confirmed to be officially released at ChinaJoy in Shanghai on July 27. It is claimed to be a mini host designed for professional AI creation. It is a performance master and an expert in AI creation of 3D digital people. The AI ​​virtual background is based on the on-site pictures provided by our friend @yuP in Shanghai. The volume of this small host is only 3.7L. It is made of anodized aluminum and is equipped with Intel Core. i7-14700 processor, equipped with 32GBDDR5 memory and 1TB solid state drive. YOGA Portal is both a host and an all-in-one AI creation machine. The high-performance host is combined with an algorithm-optimized camera to form an integrated solution. Just stand in front of the camera i.e.

Simple steps to upload your own music on Kugou Simple steps to upload your own music on Kugou Mar 25, 2024 pm 10:56 PM

1. Open Kugou Music and click on your profile picture. 2. Click the settings icon in the upper right corner. 3. Click [Upload Music Works]. 4. Click [Upload Works]. 5. Select the song and click [Next]. 6. Finally, click [Upload].

MSI showcases MEG Vision MSI showcases MEG Vision Jun 09, 2024 am 11:15 AM

According to news from this site on June 5, MSI participated in the 2024 Taipei International Computer Show and showcased a new flagship gaming computer called MEGVisionXAI. This game console is an extension of the existing Vision series and uses a very eye-catching surround glass design, with internal components clearly visible. The most attractive part is that the front of the host is equipped with an oversized touch screen. MSI staff said that it can synchronize MSI’s exclusive AI applications to further enhance various AI functions. The relevant pictures attached to this site are as follows: MSI has not yet explained more details. From the pictures shared, you can see that a local AI chatbot is running on the screen. Users can interact with it and ask it to complete AI tasks and locate locally stored documents. wait. Source of the above picture:

A must-have for veterans: Tips and precautions for * and & in C language A must-have for veterans: Tips and precautions for * and & in C language Apr 04, 2024 am 08:21 AM

In C language, it represents a pointer, which stores the address of other variables; & represents the address operator, which returns the memory address of a variable. Tips for using pointers include defining pointers, dereferencing pointers, and ensuring that pointers point to valid addresses; tips for using address operators & include obtaining variable addresses, and returning the address of the first element of the array when obtaining the address of an array element. A practical example demonstrating the use of pointer and address operators to reverse a string.

What are the tips for novices to create forms? What are the tips for novices to create forms? Mar 21, 2024 am 09:11 AM

We often create and edit tables in excel, but as a novice who has just come into contact with the software, how to use excel to create tables is not as easy as it is for us. Below, we will conduct some drills on some steps of table creation that novices, that is, beginners, need to master. We hope it will be helpful to those in need. A sample form for beginners is shown below: Let’s see how to complete it! 1. There are two methods to create a new excel document. You can right-click the mouse on a blank location on the [Desktop] - [New] - [xls] file. You can also [Start]-[All Programs]-[Microsoft Office]-[Microsoft Excel 20**] 2. Double-click our new ex

Create and run Linux ".a" files Create and run Linux ".a" files Mar 20, 2024 pm 04:46 PM

Working with files in the Linux operating system requires the use of various commands and techniques that enable developers to efficiently create and execute files, code, programs, scripts, and other things. In the Linux environment, files with the extension ".a" have great importance as static libraries. These libraries play an important role in software development, allowing developers to efficiently manage and share common functionality across multiple programs. For effective software development in a Linux environment, it is crucial to understand how to create and run ".a" files. This article will introduce how to comprehensively install and configure the Linux ".a" file. Let's explore the definition, purpose, structure, and methods of creating and executing the Linux ".a" file. What is L

See all articles