简体   繁体   English

将本地数据库从一台计算机复制到另一台计算机

[英]Copying a local database from one computer to another

I'm very new to SQL and made a small program where a user can input some data, click submit and the data is then stored in a table in the database. 我是SQL的新手,并创建了一个小程序,用户可以在其中输入一些数据,单击提交,然后将数据存储在数据库的表中。

I know want to move the application onto a friends computer, which i'm assuming has no SQL software installed, what would be the easiest way to do this, when obviously the connection string is unique to my computer and the database is stored on my computer. 我知道想要将应用程序移动到朋友计算机上,我假设没有安装SQL软件,最简单的方法是什么,显然连接字符串对我的计算机是唯一的,数据库存储在我的计算机上电脑。

You will have to install SQL Server on their machine first and foremost. 您必须首先在其计算机上安装SQL Server。 Once this is done, you can obtain a relevant connection string. 完成此操作后,您可以获取相关的连接字符串。 Note, for the 'Server name' part of the connection string, if you are using SQL Express, instead of using 'localhost', or the name of the server instance (ie 'MyMachine'), you would use 'localhost\\SQLEXPRESS'/'MyMachine\\SQLEXPRESS'. 请注意,对于连接字符串的“服务器名称”部分,如果您使用的是SQL Express,而不是使用“localhost”或服务器实例的名称(即“MyMachine”),则应使用“localhost \\ SQLEXPRESS” / 'MYMACHINE \\ SQLEXPRESS'。

After setting up the SQL Server instance on the new machine, to copy the required database, first detach the database to avoid any corruption. 在新计算机上设置SQL Server实例后,要复制所需的数据库,请首先分离数据库以避免任何损坏。 Now you are free to merely copy the file from your machine to theirs and go through the usual attachment process using SQL Server Management Studio (SQLMS). 现在,您可以自由地将文件从您的计算机复制到他们的计算机上,并使用SQL Server Management Studio(SQLMS)完成常规的附件过程。

I hope this helps. 我希望这有帮助。

You can use SQL CE or other file databases. 您可以使用SQL CE或其他文件数据库。 On this way you need to install SQL CE(you can include SQl CE installer into your program installer) on target computer and after that you can easy copy db-file from you computer to target computer. 在这种情况下,您需要在目标计算机上安装SQL CE(您可以在程序安装程序中包含SQl CE安装程序),然后您可以轻松地将db-file从您的计算机复制到目标计算机。

Also, you can use relative path to db-file from your exe file instead of fixed connection string: 此外,您可以使用exe文件中的db-file相对路径而不是固定连接字符串:

string dbDirPath=Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"DB" );
private const string CONN_STR_TEMPLATE = "Data Source={0};Persist Security Info=False;";
string dbFilePath = Path.Combine(dbDirPath, "my.sdf");
_connStr =String.Format(CONN_STR_TEMPLATE,dbFilePath);

You cannot simply copy your database since SQL Server database is NOT a standalone database as SQL Compact edition/MS Access. 您不能简单地复制数据库,因为SQL Server数据库不是SQL Compact版本/ MS Access的独立数据库。 You may configure your router to remote access SQL Server instance over the Internet by forwarding the port 您可以通过转发端口将路由器配置为通过Internet远程访问SQL Server实例

Accessing SQL Server Instance through NAT 通过NAT访问SQL Server实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将wpf应用程序的本地数据库从一台计算机转移到另一台计算机? - How to transfer the local database of wpf application from one computer to other? 使用C#上的参数从一个数据库复制行中的行 - Copying rows from one database from another with parameters on C# 将表从一个数据库复制到同一服务器上的另一个数据库 - Copying tables from one database to another on same server 将数据从一个数据库复制到另一个数据库-内存不足异常 - Copying data from one database to another - Out of Memory Exception 从一个 stream 复制到另一个? - Copying from one stream to another? 将一个数据库表的数据复制到另一个 - Copying the data of one database table to another 将文件从我的Azure Web角色复制到另一台计算机 - Copying a file from my Azure web role to another computer 通过我本地计算机上的 .NET Windows 应用程序将文件从一台服务器复制到另一台服务器 - Copying files from one server to another through a .NET Windows application on my local machine 使用C#将数据从一个Oracle数据库复制到另一个Oracle数据库 - Copying data from one oracle database to another oracle database using C# 在另一台计算机上使用本地数据库运行 c# 程序 - Run a c# program with local database on another computer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM