简体   繁体   English

定期将访问数据库复制到SQL Server

[英]Copy access database to SQL server periodically

I have an access 2003 database that holds all of my business data. 我有一个Access 2003数据库,其中包含我的所有业务数据。 This access database gets updated every few hours during the day. 该访问数据库在一天中每隔几个小时更新一次。

We're currently writing a website that will need to use the data from the access database. 我们当前正在编写一个网站,该网站将需要使用访问数据库中的数据。 This website (for the time being) will have only read only capabilities. 该网站(暂时)将具有只读功能。 Meaning there will only need to be one way transfer of data (Access -> SQL). 这意味着只需要一种方式进行数据传输(访问-> SQL)。

I'm imaging there's a way to perform this data migration from access to SQL server programatically. 我正在想像有一种方法可以通过编程方式从访问SQL Server进行数据迁移。 Does anyone have any links to something I can read about? 有没有人链接到我可以阅读的内容?

If this practice sounds odd, and you'd like to suggest another way to do this (or a situation where data can go both ways (Access -> SQL, SQL -> Access), that's perfectly fine. 如果这种做法听起来很奇怪,并且您想提出另一种方法(或者数据可以同时双向访问(Access-> SQL,SQL-> Access)的情况),那很好。

The company is going to continue using Access 2003 for their business functionality. 该公司将继续使用Access 2003来实现其业务功能。 There's no way around that. 没有办法解决。 But I'd like to build the (readonly) website on top of SQL Server. 但是我想在SQL Server之上构建(只读)网站。

To do the initial data migration and set the SQL Server automatically, I would use the SQL Server Migration Assistant . 要进行初始数据迁移并自动设置SQL Server,我将使用SQL Server Migration Assistant The only thing you should definitely change that I can think of would be to turn off the Identity property on any columns that have it - to be explained below (MS Access calls Identity autonumber). 您绝对可以更改的唯一可以想到的就是关闭具有该属性的任何列上的Identity属性-下文将对此进行说明(MS Access调用Identity自动编号)。 Once you have your tables loaded, you can set up a dsnless connection to the database (and tables) you just created. 装入表后,可以建立与刚刚创建的数据库(和表)的dsnless连接

I haven't used the method just linked, but I believe it allows you to use SQL Server authentication to connect to the db. 我没有使用仅链接的方法,但是我相信它允许您使用SQL Server身份验证连接到数据库。 The benefit of using this method is you can easily change which SQL Server instance and/or database your are connecting to for development and testing. 使用此方法的好处是您可以轻松更改要连接到哪个SQL Server实例和/或数据库以进行开发和测试。

There might be a better, automated way, but you can create several insert queries doing left joins from the primary key of the Access table to the SQL Server table, and putting a WHERE clause that specifies the SQL Server PrimaryKey must be null. 可能有一种更好的自动化方法,但是您可以创建多个插入查询,以执行从Access表的主键到SQL Server表的左联接,并放置一个WHERE子句以指定SQL Server PrimaryKey必须为null。 This is why you need to turn off the Identity property in the SQL Server tables, so that you can insert the new data. 这就是为什么您需要在SQL Server表中关闭Identity属性,以便可以插入新数据的原因。

Finally, put the name of each query in one function, then run the function periodically. 最后,将每个查询的名称放在一个函数中,然后定期运行该函数。

I have used Microsoft's free SQL Server Migration Assistant (SSMA) to migrate Access to SQL Server. 我已经使用了Microsoft的免费SQL Server迁移助手(SSMA)将Access迁移到SQL Server。 The tool is very simple to use. 该工具使用非常简单。 The only problem I have encountered with the tool was overloaded data types when migrating. 我使用该工具遇到的唯一问题是迁移时数据类型过载。 What I mean by this is a small string will get converted to a NVARCHAR(MAX) in some instances. 我的意思是,在某些情况下,一个小字符串将转换为NVARCHAR(MAX) Otherwise, the tool is very handy and can be reused after setting up a 'profile'. 否则,该工具非常方便,可以在设置“配置文件”后重新使用。

The strategy you outlined can be very challenging. 您概述的策略可能非常具有挑战性。 You could use INSERT queries to copy new Access rows to SQL Server, as described in another answer. 您可以使用INSERT查询将新的Access行复制到SQL Server,如另一个答案中所述。

However, if you have changes to existing Access rows, and you also want those changes propagated to SQL Server, it won't be so simple. 但是,如果对现有的Access行进行了更改,并且还希望将这些更改传播到SQL Server,它将不会那么简单。 And it will be more complicated still if you want deleted Access rows deleted from SQL Server, too. 如果您还想从SQL Server删除Access行,那将仍然更加复杂。

It seems more reasonable to me to use a different approach. 对我来说,使用其他方法似乎更合理。 Migrate the data to SQL Server once. 一次将数据迁移到SQL Server。 Then replace the tables in your Access database with ODBC links to the SQL Server tables. 然后,用到SQL Server表的ODBC链接替换Access数据库中的表。 Thereafter, changes to the data from within your Access application will not require a separate synchronization step ... they will already be in SQL Server. 之后,从Access应用程序中对数据进行的更改将不需要单独的同步步骤...它们已经在SQL Server中。 And you won't need to write any code to synchronize them. 而且您无需编写任何代码即可同步它们。

If your concern is that the connections between the web server and SQL Server be read-only, just set them up that way. 如果您担心Web服务器和SQL Server之间的连接是只读的,只需以这种方式进行设置即可。 You can still independently allow read-write permissions for your Access application. 您仍然可以独立地允许Access应用程序具有读写权限。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM