简体   繁体   English

从访问连接到sql server

[英]connecting to sql server from access

So Im in the process of connecting Access to SqlServer. 所以我正在连接Access到SqlServer。 What I need to do is: 我需要做的是:

  • connect the Tables (dont via upsize wizard) 连接表 (不要通过upsize向导)
  • the queries (not working out because the Microsfot SqlServer Migration Assitant couldnt deal with the external variables from the forms as well as some unknown functions) 查询 (没有解决,因为Microsfot SqlServer Migration Assitant无法处理表单中的外部变量以及一些未知函数)
  • The reports , which I havent even started 报告 ,我甚至没有开始

So that way the only thing done on the client machine is using the forms in Access, and the queries, reports, and data are all dealt with on the server. 因此,在客户端计算机上执行的唯一操作是使用Access中的表单,并且查询,报告和数据都在服务器上处理。

I guess my question is how to properly migrate these queries? 我想我的问题是如何正确迁移这些查询? I dont know how Im going to connect the queries to the Access forms to resolve these external variable errors like: 我不知道如何将查询连接到Access表单以解决这些外部变量错误,如:

SELECT AcuteHospitals.HospitalName, Sum(IIf([Quarterly CLABSI Numbers by Hospital]![Number of CLABSI] Is Null,"--",[Quarterly CLABSI Numbers by Hospital]![Number of CLABSI])) AS CLABSI, Sum(IIf([Quarterly CLABSI Numbers by Hospital]![Central Line Days] Is Null,"--",IIf([Quarterly CLABSI Numbers by Hospital]![Central Line Days]=0,0,Format([Quarterly CLABSI Numbers by Hospital]![Central Line Days],"#,###")))) AS CLD, [Quarterly CLABSI Numbers by Hospital].SizeCat, [Quarterly CLABSI Numbers by Hospital].BedSize
FROM AcuteHospitals LEFT JOIN [Quarterly CLABSI Numbers by Hospital] ON AcuteHospitals.HospitalName = [Quarterly CLABSI Numbers by Hospital].HospitalName
WHERE ((([Quarterly CLABSI Numbers by Hospital].SummaryYQ) In ("2010Q1","2010Q2")))
GROUP BY AcuteHospitals.HospitalName, [Quarterly CLABSI Numbers by Hospital].SizeCat, [Quarterly CLABSI Numbers by Hospital].BedSize
ORDER BY AcuteHospitals.HospitalName;

gives me the following errors: 给我以下错误:

SSMA warning messages:
*   A2SS0030: View '2010Q1-Q2 CLABSI Rate by Hospitalstep1test' has a name that might cause problems for the Access application to function correctly against SQL Server.
*/


   /* 
   *   SSMA error messages:
   *   A2SS0069: External variable cannot be converted.

   *   A2SS0061: The identifier 'Format(UNKNOWN, VARCHAR)' was not converted.

I've fixed the Format error but I dont know how to resolve the other ones 我修复了格式错误,但我不知道如何解决其他问题

The recommended approach here is to upsize ONLY your data to SQL server. 这里推荐的方法是仅将数据升级到SQL Server。

You then simply link the Access "front end" to the SQL database. 然后,您只需将Access“前端”链接到SQL数据库。

You DO NOT want to create or use an access data project. 您不想创建或使用访问数据项目。

In fact as a general rule it's far better split your database first. 事实上,作为一般规则,首先分割数据库要好得多。 And in fact if this application had been developed and maintained correctly over the years, it's pretty much a given that at 1. In time it was split into a front end or so called application part, and that of a backend which is the data only part. 事实上,如果这个应用程序多年来已经正确开发和维护,那么它几乎是给定的.1。它被分成前端或所谓的应用程序部分,后端分为仅数据部分。

It is the data only that you want to send up to SQL server, you do not want to convert your application to a data project, or do anything else which will result in you having to rewrite a your VBA code and that of having to rebuild your queries. 它只是您要发送到SQL服务器的数据,您不希望将应用程序转换为数据项目,或者执行任何其他操作,这将导致您必须重写您的VBA代码以及必须重建你的疑问。

So you take the DATA ONLY part and upsize the data to SQL server. 因此,您将获取DATA ONLY部分并将数据升迁到SQL Server。 The result is usually the upsizing wizard will create linked tables for you. 结果通常是升迁向导将为您创建链接表。 Do not create an access data project here, simply upsize your data. 不要在此处创建访问数据项目,只需升级数据即可。

At this point you can import those table links to from your back end into your front end, or simply delete your existing table links you have in your access front end, and now RE link those tables to SQL server . 此时,您可以将这些表链接从后端导入到前端,或者只是删除访问前端中现有的表链接,现在将这些表链接到SQL服务器。

At this point in time all of your current queries will continue to function, and all of your current queries will not be have to be rewritten. 此时,所有当前查询将继续运行,并且不必重写所有当前查询。

There's no need whatsoever to recreate all of your queries. 没有必要重新创建所有查询。 The only time you'll have to recreate some queries is perhaps for reasons of performance. 您唯一需要重新创建一些查询的时间可能是出于性能原因。 That is something you can worry about and work on over time. 这是你可以担心和长期工作的事情。 You will also find that 99% of your VBA and even DAO recordset code will continue to run just fine. 您还会发现99%的VBA甚至DAO记录集代码都将继续正常运行。

If you upsize to an Access Data Project (ADP), then you have to re-write any DAO code in your VBA. 如果升迁到Access数据项目(ADP),则必须在VBA中重写任何DAO代码。 And you MUST use ADO which as noted Microsoft has quite said it's much on its way out. 并且你必须使用ADO,正如微软已经说的那样,ADO已经走了很多路。 Microsoft as stated that the future technology is ODBC and for Access that means DAO. 微软表示,未来的技术是ODBC,而Access则意味着DAO。

If you want to upsize your tables to the latest and greatest eddition of SQL server called Azure, the ONLY support baked into Access 2010 which as stated future road technology is using linked tables (ODBC). 如果您希望将表升迁到称为Azure的SQL服务器的最新和最好的版本,那么唯一的支持就是Access 2010,而未来的道路技术正在使用链接表(ODBC)。 So in Access this means you are to continue using DAO. 所以在Access中这意味着你要继续使用DAO。

If your application did use ADO, then I STILL recommend using linked tables to SQL server as opposed to an attempted conversion of Access database to a ADP project. 如果您的应用程序确实使用了ADO,那么我仍然建议将链接表用于SQL服务器,而不是尝试将Access数据库转换为ADP项目。

So, using linked tables means your existing queries will not have to be modified. 因此,使用链接表意味着您不必修改现有查询。

It's just saying it can't convert this to SQL Server dialect: 它只是说它无法将其转换为SQL Server方言:

Format([Quarterly CLABSI Numbers by Hospital]![Central Line Days],"#,###"))))

Because T-SQL doesn't have a format function, this is at least defensible. 因为T-SQL没有格式化功能,所以这至少是可以防御的。

The way I last converted an Access database was: 我上次转换Access数据库的方式是:

  1. Importing the tables into SQL Server 将表导入SQL Server
  2. Create an empty .ADB file. 创建一个空的.ADB文件。 Those files use SQL Server as their backend. 这些文件使用SQL Server作为后端。
  3. Then, one by one, I import the forms and reports from the old MDB to the new ADB. 然后,我逐个将表单和报告从旧MDB导入到新ADB。 Each one can take anything from small changes to a complete rewrite. 每个人都可以从小变化到完全重写。

现在支持SQL 2012中的FORMAT功能。

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

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