简体   繁体   English

MS Access应用程序-将数据存储从Access转换为SQL Server

[英]MS Access Application - Convert data storage from Access to SQL Server

Bear in mind here, I am not an Access guru. 请记住,我不是Access专家。 I am proficient with SQL Server and .Net framework. 我精通SQL Server和.Net框架。 Here is my situation: 这是我的情况:

A very large MS Access 2007 application was built for my company by a contractor. 承包商为我的公司构建了一个非常大型的MS Access 2007应用程序。

The application has been split into two tiers BY ACCESS; 该应用程序已按访问权限分为两层: there is a front end portion that holds all of the Ms Access forms, and then on the back end part, which are access tables, queries, etc., that is stored on a computer on the network. 有一个前端部分保存所有Ms Access表单,然后在后端部分保存访问表,查询等,这些表格存储在网络上的计算机上。

Well, of course, there is a need to convert the data storage portion to SQL Server 2005 while keeping all of these GUI forms which were built in Ms Access. 好吧,当然,有必要将数据存储部分转换为SQL Server 2005,同时保留所有在Ms Access中内置的GUI表单。 This is where I come in. 这是我进来的地方。

I have read a little, and have found that you can link the forms or maybe even the access tables to SQL Server tables, but I am still very unsure on what exactly can be done and how to do it. 我读了一点,发现可以将表格甚至访问表链接到SQL Server表,但是我仍然不确定到底可以做什么以及如何做。

Has anyone done this? 有人这样做吗? Please comment on any capabilities, limitations, considerations about such an undertaking. 请评论有关此任务的任何功能,限制和注意事项。 Thanks! 谢谢!

Do not use the upsizing wizard from Access: 不要使用Access中的升迁向导:

  • First, it won't work with SQL Server 2008. 首先,它不适用于SQL Server 2008。

  • Second, there is a much better tool for the job: 其次,有一个更好的工具可以完成这项工作:
    SSMA, the SQL Server Migration Assistant for Access which is provided for free by Microsoft. SSMA,Microsoft免费提供的Access SQL Server迁移助手

It will do a lot for you: 它会为您做很多事情:

  • move your data from Access to SQL Server 将数据从Access移到SQL Server
  • automatically link the tables back into Access 自动将表链接回Access
  • give you lots of information about potential issues due to differences in the two databases 由于两个数据库的差异,为您提供了大量有关潜在问题的信息
  • keeps track of the changes so you can keep the two synchronised over time until your migration is complete. 跟踪更改,以便随着时间的推移使两者保持同步,直到迁移完成。

I wrote a blog entry about it recently. 我最近写了一篇博客文章

You have a couple of options, the upsizing wizard does a decent(ish) job of moving structure and data from access to Sql. 您有两个选择, 升迁向导可以很好地完成将结构和数据从对Sql的访问中移出的工作。 You can then setup linked tables so your application 'should' work pretty much as it does now. 然后,您可以设置链接表,以便您的应用程序“应该”像现在一样正常工作。 Unfortunately the Sql dialect used by Access is different from Sql Server, so if there are any 'raw sql' statements in the code they may need to be changed. 不幸的是,Access使用的Sql方言不同于Sql Server,因此,如果代码中有任何“原始sql”语句,则可能需要更改它们。

As you've linked to tables though all the other features of Access, the QBE, forms and so on should work as expected. 尽管您已经链接到表,但是Access的所有其他功能,QBE,表单等都应该可以正常工作。 That's the simplest and probably best approach. 那是最简单,可能也是最好的方法。

Another way of approaching the issue would be to migrate the data as above, and then rather than using linked tables, make use of ADO from within access. 解决该问题的另一种方法是如上所述地迁移数据,然后在访问中使用ADO而不是使用链接表。 That approach is kind of famaliar if you're used to other languages/dev environments, but it's the wrong approach. 如果您习惯于其他语言/开发环境,则该方法有点麻烦,但这是错误的方法。 Access comes with loads of built in stuff that makes working with data really easy, if you go back to use ADO/Sql you then lose many of those benefits. Access带有大量内置的东西,使处理数据变得非常容易,如果您回头使用ADO / Sql,则会失去很多好处。

I suggest start on a small part of the application - non essential data, and migrate a few tables and see how it goes. 我建议从应用程序的一小部分开始-非必要数据,然后迁移一些表并查看其运行方式。 Of course you back everything up first. 当然,您首先要备份所有内容。

Good luck 祝好运

Others have suggested upsizing the Jet back end to SQL Server and linking via ODBC. 其他人建议将Jet后端升级到SQL Server,并通过ODBC进行链接。 In an ideal world, the app will work beautifully without needing to change anything. 在理想的世界中,该应用程序可以完美运行,而无需进行任何更改。

In the real world, you'll find that some of your front-end objects that were engineered to be efficient and fast with a Jet back end don't actually work very well with a server database. 在现实世界中,您会发现某些通过Jet后端高效而快速地设计的前端对象实际上无法很好地与服务器数据库配合使用。 Sometimes Jet guesses wrong and sends something really inefficient to the server. 有时,Jet会猜错并向服务器发送一些效率很低的东西。 This is particular the case with mass updates of records -- in order not to hog server resources (a good thing), Jet will send a single UPDATE statement for each record (which is a bad thing for your app, since it's much, much slower than a single UPDATE statement). 大规模更新记录时尤其如此-为了不占用服务器资源(一件好事),Jet将为每条记录发送一条UPDATE语句(这对您的应用程序来说是一件坏事,因为它很多很多)比单个UPDATE语句慢)。

What you have to do is evaluate everything in your app after you've upsized it and where there are performance problems, move some of the logic to the server. 您需要做的是在应用放大后评估所有内容,并在出现性能问题的地方将一些逻辑转移到服务器上。 This means you may create a few server-side views, or you may use passthrough queries (to hand off the whole SQL statement to SQL Server and not letting Jet worry about it), or you may need to create stored procedures on the server (especially for update operations). 这意味着您可以创建一些服务器端视图,或者可以使用直通查询(将整个SQL语句移交给SQL Server,而不必让Jet担心),或者您可能需要在服务器上创建存储过程(特别是对于更新操作)。

But in general, it's actually quite safe to assume that most of it will work fine without change. 但总的来说,假设大多数内容无需更改即可正常工作,这实际上是相当安全的。 It likely won't be as fast as the old Access/Jet app, but that's where you can use SQL Profiler to figure out what the holdup is and re-architect things to be more efficient with the SQL Server back end. 它的运行速度可能不如旧的Access / Jet应用程序快,但是您可以在此处使用SQL Profiler找出保留的内容,并重新构建架构,以使用SQL Server后端提高效率。

If the Access app was already efficiently designed (eg, forms are never bound to full tables, but instead to recordsources with restrictive WHERE clauses returning only 1 or a few records), then it will likely work pretty well. 如果Access应用程序已经进行了有效的设计(例如,窗体从不绑定到完整表,而是绑定到具有限制性WHERE子句的记录源仅返回1个或几条记录),那么它可能会很好地工作。 On the other hand, if it uses a lot of the bad practices seen in the Access sample databases and templates, you could run into huge problems. 另一方面,如果它使用Access示例数据库和模板中看到的许多不良做法,则可能会遇到很多问题。

It's my opinion that every Access/Jet app should be designed from the beginning with the idea that someday it will be upsized to use a server back end. 我认为,每个Access / Jet应用程序都应该从一开始就设计,其想法是有一天它将扩大到使用服务器后端。 This means that the Access/Jet app will actually be quite efficient and speedy, but also that when you do upsize, it will cause a minimum of pain. 这意味着Access / Jet应用程序实际上将非常高效,快捷,但是当您进行超大型安装时,它将减少痛苦。

This is your lowest-cost option. 这是您成本最低的选择。 You're going to want to set up an ODBC connection for your Access clients pointing to your SQL Server. 您将要为指向SQL Server的Access客户端建立ODBC连接。 You can then use the (I think) "Import" option to "link" a table to the SQL Server via the ODBC source. 然后,您可以使用(我认为)“导入”选项通过ODBC源将表“链接”到SQL Server。 Migrate your data from the Access tables to SQL Server, and you have your data on SQL Server in a form you can manage and back up. 将数据从Access表迁移到SQL Server,然后以可以管理和备份的形式在SQL Server上存储数据。 Important, queries can then be written on SQL Server as views and presented to the Access db as linked tables as well. 重要的是,查询随后可以作为视图写在SQL Server上,也可以作为链接表呈现给Access db。

Take a look at this Access to SQL Server migration tool. 看一下这个Access to SQL Server迁移工具。 It might be one of the few, if not the ONLY, true peer-to-peer or server-to-server migration tools running as a pure Web Application. 它可能是作为纯Web应用程序运行的少数几个(如果不是唯一的)真正的对等或服务器到服务器迁移工具之一。 It uses mostly ASP 3.0, XML, the File System Object, the Data Dictionary Object, ADO, ADO Extensions (ADOX), the Dictionary Scripting Objects and a few other neat Microsoft techniques and technologies. 它主要使用ASP 3.0,XML,文件系统对象,数据字典对象,ADO,ADO扩展(ADOX),字典脚本对象和其他一些简洁的Microsoft技术。 If you have the Source Access Table on one server and the destination SQL Server on another server or even the same server and you want to run this as a Web Internet solution this is the product for you. 如果您在一台服务器上具有源访问表,而另一台服务器甚至是同一台服务器上具有目标SQL Server,并且希望将其作为Web Internet解决方案来运行,那么这就是您的产品。 This example discusses the VPASP Shopping Cart, but it will work for ANY version of Access and for ANY version of SQL Server from SQL 2000 to SQL 2008. 此示例讨论了VPASP购物车,但它将适用于Access的任何版本以及从SQL 2000到SQL 2008的任何版本的SQL Server。

I am finishing up development for a generic Database Upgrade Conversion process involving the automated conversion of Access Table, View and Index Structures in a VPASP Shopping or any other Access System to their SQL Server 2005/2008 equivalents. 我正在完成通用数据库升级转换过程的开发,该过程涉及将VPASP Shopping或任何其他访问系统中的访问表,视图和索引结构自动转换为SQL Server 2005/2008等效项。 It runs right from your server without the need for any outside assistance from external staff or consultants. 它可以直接从您的服务器运行,而无需外部人员或顾问的任何外部帮助。

After creating a clone of your Access tables, indexes and views in SQL Server this data migration routine will selectively migrate all the data from your Access tables into your new SQL Server 2005/2008 tables without having to give out either your actual Access Database or the Table Contents or your passwords to anyone. 在SQL Server中创建Access表,索引和视图的克隆后,此数据迁移例程将有选择地将所有数据从Access表迁移到新的SQL Server 2005/2008表中,而不必给出实际的Access数据库或数据库。表内容或您的密码给任何人。

Here is the Reverse Engineering part of the process running against a system with almost 200 tables and almost 300 indexes and Views which is being done as a system acceptance test. 这是针对具有约200个表,近300个索引和视图的系统运行的过程的逆向工程部分,这是作为系统验收测试而完成的。 Still a work in progress, but the core pieces are in place. 仍在进行中,但核心部分已经就绪。

http://www.21stcenturyecommerce.com/SQLDDL/ViewDBTables.asp http://www.21stcenturyecommerce.com/SQLDDL/ViewDBTables.asp

I do the automated reverse engineering of the Access Table DDLs (Data Definition Language) and convert them into SQL equivalent DDL Statements, because table structures and even extra tables might be slightly different for every VPASP customer and for every version of VP-ASP out there. 我做访问表的DDL(数据定义语言)的自动化逆向工程,将其转换成SQL相当于DDL语句,因为表的结构,甚至额外的表可能是每一个VPASP客户和VPASP的每个版本在那里略有不同。

I am finishing the actual data conversion routine which would migrate the data from Access to SQL Server after these new SQL Tables have been created including any views or indexes. 我正在完成实际的数据转换例程,该例程将在创建这些新的SQL表(包括任何视图或索引)之后将数据从Access迁移到SQL Server。 It is written entirely in ASP, with VB Scripting, the File System Object (FSO), the Dictionary Object, XML, DHTML, JavaScript right now and runs pretty quickly as you will see against a SQL Server 2008 Database just for the sake of an example. 它完全是用ASP编写的,带有VB脚本,文件系统对象(FSO),字典对象,XML,DHTML,JavaScript现在,并且运行很快,就像针对SQL Server 2008数据库看到的那样。例。

It takes perhaps 15-20 seconds to reverse engineer almost 500 different database objects. 对大约500个不同的数据库对象进行反向工程大约需要15-20秒。 There might be a total of over 2,000 columns involved in this example for the 170 tables and 270 indexes involved. 此示例中涉及的170个表和270个索引可能总共涉及2,000多个列。

I have even come up with a way for you to run both VPASP systems in parallel using 2 different database connection files on the same server just to be sure that orders entered on the Access System and the SQL Server system produce the same results before actual cutover to production. 我什至想出了一种方法,让您在同一服务器上使用2个不同的数据库连接文件并行运行两个VPASP系统,以确保在实际转换之前在Access System和SQL Server系统上输入的订单产生相同的结果。生产。

John (a/k/a The SQL Dude) sales@designersyles.biz (This is a VP-ASP Demo Site) John(a / k / a SQL Dude)sales@designersyles.biz(这是VP-ASP演示站点)

Linked Access tables work fine but I've only used them with ODBC and other databases (Firebird, MySQL, Sqlite3). 链接访问表工作正常,但我仅将它们用于ODBC和其他数据库(Firebird,MySQL,Sqlite3)。 Information on primary or foreign keys wasn't passing through. 没有传递有关主键或外键的信息。 There were also problems with datatype interpretation: a date in MySQL is not the same thing as in Access VBA. 数据类型解释也存在问题:MySQL中的日期与Access VBA中的日期不同。 I guess these problems aren't nearly as bad when using SQL Server. 我猜这些问题在使用SQL Server时并没有那么糟糕。

Important Point: If you link the tables in Access to SQL Server, then EVERY table must have a Primary Key defined (Contractor? Access? Experience says that probably some tables don't have PKs). 要点:如果您将Access中的表链接到SQL Server,则每个表都必须定义一个主键(Contractor?Access?经验表明,某些表可能没有PK)。 If a PK is not defined, then the Access forms will not be able to update and insert rows, rendering the tables effectively read-only. 如果未定义PK,则Access窗体将无法更新和插入行,从而使表实际上是只读的。

Here is a technique I've heard one developer speak on. 我听说过一位开发人员在讲的一种技术。 This is if you really want something like a Client-Server application. 这是如果您确实想要类似客户端服务器应用程序的东西。

  1. Create .mdb/.mde frontend files distributed to each user (You'll see why). 创建分发给每个用户的.mdb / .mde前端文件(您将看到原因)。
  2. For every table they need to perform an CRUD, have a local copy in the file in #1. 对于每个需要执行CRUD的表,在#1中的文件中有一个本地副本。
  3. The forms stay linked to the local tables. 表单保持链接到本地​​表。
  4. Write VBA code to handle the CRUD from the local tables to the SQL Server database. 编写VBA代码以处理从本地表到SQL Server数据库的CRUD。
  5. Reports can be based off of temp tables created from the SQL Server (Won't be able to create temp tables in mde file I don't think). 报表可以基于从SQL Server创建的临时表(我认为无法在mde文件中创建临时表)。

Once you decide how you want to do this with a single form, it is not too difficult to apply the same technique to the rest. 一旦确定了如何使用单个表格来完成此操作,则将相同的技术应用于其余的表格并不太困难。 The nice thing about working with the form on a local table is you can keep a lot of the existing functionality as the existing application (Which is why they used and continue to use Access I hope). 关于在本地表上使用表单的好处是,您可以将许多现有功能保留为现有应用程序(这就是为什么我希望并继续使用Access的原因)。 You just need to address getting data back and forth to the SQL Server. 您只需要解决将数据来回传递到SQL Server的问题。

You can continue to have linked tables, and then gradually phase them out with this technique as time and performance needs dictate. 您可以继续拥有链接表,然后根据时间和性能需求逐步使用此技术逐步淘汰它们。

Since each user has their own local file, they can work on their local copy of the data. 由于每个用户都有自己的本地文件,因此他们可以处理其数据的本地副本。 Only the minimum required to do their task should ever be copied locally. 仅应将完成其任务所需的最低要求复制到本地。 Example: if they are updating a single record, the table would only have that record. 示例:如果他们正在更新单个记录,则表将仅具有该记录。 When a user adds a new record, you would notice that the ID field for the record is Null, so an insert statement is needed. 用户添加新记录时,您会注意到该记录的ID字段为Null,因此需要插入语句。

I guess the local table acts like a dataset in .NET? 我猜本地表的行为就像.NET中的数据集吗? I'm sure in some way this is an imperfect analogy. 我确信这在某种程度上是不完美的比喻。

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

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