简体   繁体   English

Microsoft Access ODBC连接:连接字符串差异

[英]Microsoft Access ODBC Connections: Connection String Differences

Using the following: 使用以下内容:

  • MS Access 2016, Office 365 MS Access 2016,Office 365
  • SQL Server 2012 SQL Server 2012

I have 100+ SQL Server tables and views linked into an Access database via ODBC connection. 我有100多个SQL Server表和视图通过ODBC连接链接到Access数据库。 All of these SQL Server objects are from two SQL Server databases that reside on the same server. 所有这些SQL Server对象都来自驻留在同一服务器上的两个SQL Server数据库。 All of these connections have been set up using the Access user interface and re-linked via the Linked Table Manager. 所有这些连接都已使用Access用户界面进行了设置,并通过链接表管理器进行了重新链接。

I've been experiencing a number of Access database issues lately, so I'm combing through everything with a fine-tooth comb. 我最近遇到了许多Access数据库问题,因此我正在用细齿梳来梳理所有内容。 I noticed that the connection strings for all my SQL Server objects have a number of inconsistencies (see below). 我注意到所有SQL Server对象的连接字符串都有许多不一致之处(请参见下文)。 There does not seem to be any pattern in terms of when these objects where created and the format of the connection string either. 就何时创建​​这些对象以及连接字符串的格式而言,似乎没有任何模式。

ODBC;DSN=Database1;Description=Database1;Trusted_Connection=Yes;APP=Microsoft Office 2010;  
ODBC;DSN=Database1;Description=Database1;Trusted_Connection=Yes;APP=Microsoft Office 2010;DATABASE=Database1  
ODBC;DSN=Database1;Description=Database1;Trusted_Connection=Yes;APP=Microsoft Office 2010;DATABASE=Database1;Network=DBMSSOCN  
ODBC;DSN=Database1;Description=Database1;Trusted_Connection=Yes;APP=Microsoft Office 2016;  
ODBC;DSN=Database1;Description=Database1;Trusted_Connection=Yes;APP=Microsoft Office 2016;DATABASE=Database1  
ODBC;DSN=Database2;Description=Database2;Trusted_Connection=Yes;APP=Microsoft Office 2010;DATABASE=Database2  
ODBC;DSN=Database2;Description=Database2;Trusted_Connection=Yes;APP=Microsoft Office 2016;DATABASE=Database2  

Is it problematic that there are so many variations of the connection string? 连接字符串的变化太多有问题吗? I've done some research (ie, Googling), but I don't much experience in this area of databases. 我已经做过一些研究(例如Googling),但是我在数据库领域没有太多经验。 Some connections have a "Network" specified, but others don't. 一些连接指定了“网络”,而其他则没有。 Per connectionstrings.com ( https://www.connectionstrings.com/define-sql-server-network-protocol/ ), “Network=DBMSSOC” specifies a Winsock TCP/IP connection, which I believe is the appropriate choice for my network setup. 对于每个connectionstrings.com( https://www.connectionstrings.com/define-sql-server-network-protocol/ ),“ Network = DBMSSOC”指定Winsock TCP / IP连接,我认为这是我的网络的适当选择设定。 Is it problematic that this parameter is excluded from several of the connection strings? 从多个连接字符串中排除此参数是否有问题?

I would most certainly “harmonize” all of the linked tables to the same connection. 我当然可以将所有链接表“协调”到同一连接。

You can use the linked table manager to do this, but likely code is better. 您可以使用链接表管理器执行此操作,但是可能代码会更好。

You need to select all tables in the linked table manager, and MAKE sure you click on prompt for new location. 您需要在链接的表管理器中选择所有表,并确保单击提示输入新位置。 This will force you to create (or select) an existing DSN. 这将迫使您创建(或选择)现有的DSN。 In fact, I would select all tables from the “one” given database, and then click on the “always” prompt for new location. 实际上,我将从“一个”给定的数据库中选择所有表,然后单击“始终”提示以查找新位置。 When you do this, then all will posies the SAME link and connection string. 当您执行此操作时,所有程序都将具有SAME链接和连接字符串。

There are good number of reasons, one good reason is Access will cache the connection for you. 原因有很多,其中一个很好的原因是Access会为您缓存连接。 So if you have “different” connections for the same database, you will have multiple caches of those connections. 因此,如果同一数据库具有“不同”的连接,则这些连接将具有多个缓存。 This likely will not affect performance “much”, but it still a good idea. 这可能不会很大程度地影响性能,但这仍然是一个好主意。

And if you are NOT using a trusted connection, then your connection strings in fact do NOT need to include the uid/password. 而且,如果您不使用受信任的连接,那么实际上您的连接字符串不需要包含uid /密码。 (However, the cache of the uid/password requires exact string matches (minus the uid/password). In this approach, you can execute a “one time” logon on application start up, and then all linked tables (without the uid/password) will now work. However, you using trusted connections here, so this tip + issue don't matter. (但是,uid / password的高速缓存需要完全匹配的字符串(减去uid / password)。在这种方法中,您可以在应用程序启动时执行“一次性”登录,然后执行所有链接表(无需uid /密码)现在可以使用,但是,您在此处使用了受信任的连接,因此此提示+问题无关紧要。

In your example, you using trusted connections, so issues are “much” less of a worry or problem. 在您的示例中,您使用的是受信任的连接,因此,问题“少得多”了,省心又省力。

I also STRONG suggest that when you launch the ODBC manager from Access, that you ALWAYS but ALWAYS use a FILE dsn. 我也强烈建议从Access启动ODBC管理器时,总是但总是使用FILE dsn。 The reason for this is that then Access will convert the connections to DSN-less for you. 原因是Access会为您将连接转换为无DSN。

This means that you can now deploy the front end application to any workstation, and you don't need to setup or have any DSN connection copied, or even setup on the workstation. 这意味着您现在可以将前端应用程序部署到任何工作站,并且无需设置或复制任何DSN连接,甚至无需在工作站上进行设置。

So I would in fact select all of the tables for one given database, (check the prompt for new location), and then create a FILE dsn (they are the default anyway). 因此,实际上我会为一个给定的数据库选择所有表(检查提示是否有新位置),然后创建一个FILE dsn(无论如何它们都是默认值)。 Once you link, then do the same for all the other tables that point to the other database. 链接后,请对指向其他数据库的所有其他表执行相同的操作。 Again re-link. 再次重新链接。

The result will be a dsn-less connection, and thus your application will work on any workstation on the network, and do so without having to setup a dsn of any kind on each workstation. 结果将是无dsn的连接,因此您的应用程序将可以在网络上的任何工作站上运行,而无需在每个工作站上设置任何类型的dsn。

So yes, you don't have to, but it seems over time, some tables were linked using a different DSN, they should be harmonized. 所以是的,您不必一定要这样做,但是随着时间的流逝,似乎有些表是使用不同的DSN链接的,它们应该保持一致。 And if you ever introduce some automatic linking code, you want to be able to distinguish between the two databases, and you code will have a rather difficult time doing this with a “hodge” podge of differing connections. 而且,如果您引入了一些自动链接代码,则希望能够区分这两个数据库,并且您将很难通过连接不同的“杂物箱”来进行编码。

So you can use the linked table manger to harmonizing the connections – just ensure you select all tables from a single given database, and then re-link with a FILE dsn, the result will be a DSN less connection (access will ONLY use the DSN during the linking process – after that, access don't care, nor does it use or even look at the DSN, or even if it exists. 因此,您可以使用链接表管理器来协调连接–只需确保从单个给定数据库中选择所有表,然后与FILE dsn重新链接,结果将减少DSN连接(访问将仅使用DSN在链接过程中–之后,访问无关紧要,它也不使用甚至不查看DSN,甚至不存在。

Having said all of the above, it not clear if this issue is related to your errors, or instabilities in your application. 综上所述,尚不清楚此问题是否与您的错误或应用程序中的不稳定有关。 (a good idea is to always distribute a compiled version of your application - (a accDE as opposed to accDB). (一个好主意是始终分发应用程序的编译版本-(与accDB相对应的accDE)。

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

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