我正在使用 .NET 连接器访问 MySQL 数据库并收到错误“Guid 应包含 32 位数字和 4 个破折号”

发布于 2024-08-15 12:29:44 字数 377 浏览 2 评论 0原文

我有一个 .NET 应用程序,它允许用户通过提供连接字符串和提供程序来访问各种数据库。

用户想要访问的数据库之一是 MySQL 数据库(不是我的,所以我无法更改它),其中主键全部存储为 GUID。

使用 MySQL ODBC 3.51 驱动程序时,我的应用程序可以访问该数据库中各个表中的记录。

但使用完全相同的代码(考虑到 ODBC 需要用 ? 代替参数名称,而 .NET 连接器需要“@name”语法),并尝试读取相同表中的相同记录,但这次使用MySQL .NET Connector(V6.1.3 以及 v6.2.2),然后我收到错误“Guid 应包含 32 位数字和 4 个破折号...”。

.NET 连接器是否有问题,或者我需要在某处指定某些内容才能使其正常工作?

I have a .NET application which allows users to access various databases by providing a connection string and a provider.

One of the databases which users want to access is a MySQL database (not mine so I can't change it) where the primary keys are all stored as GUIDs.

My application can access records in various tables in that database when using the MySQL ODBC 3.51 Driver.

But using exactly the same code (taking into account that ODBC needs a ? in place of a parameter name whereas the .NET connector needs the "@name" syntax), and attempting to read the same records in the same tables but this time with the MySQL .NET Connector (V6.1.3 as well as v6.2.2), then I get the error "Guid should contain 32 digits with 4 dashes ...".

Is there something wrong with the .NET Connector, or is there something I need to specify somewhere to make it work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生生不灭 2024-08-22 12:29:44

嗯,经过一番考察后,我想看看 MySQL 是否发布了比我更高版本的 .NET Connector。我发现 https://dev.mysql.com/downloads/connector/net/。这说明了我收到的错误,并谈到了连接字符串中的选项“old guiids=true”(它没有说明何时以及如何使用它,但它在版本中无法正常工作6.1.3)。

我尝试将“oldguids=true”放入连接字符串中,然后我的通用应用程序开始工作。

Well, after scouting around a bit, I thought I would see if MySQL had released a later version of the .NET Connector than I had. I found https://dev.mysql.com/downloads/connector/net/. That says something about the error that I was receiving, and speaks about an option "old guids=true" in the connection string (it doesn't say when and how you should use this, but that it didn't work properly in version 6.1.3).

I tried putting "oldguids=true" in my connection string, and then my generic application worked.

小清晰的声音 2024-08-22 12:29:44

我遇到了同样的问题,但它是由一个存储过程引起的,在该存储过程中我声明了一个 Char(36) 类型的变量,而 MySql(我猜连接器)将其解释为 GUID 。因此,通过将其大小更改为 37(或其他),它就起作用了。

I had the same problem, but it was caused by a Stored Procedure in which I was declaring a variable of type Char(36) and MySql (I'm guessing the Connector) was interpreting that as a GUID. So by changing its size to 37 (or whatever) it worked.

遥远的绿洲 2024-08-22 12:29:44
server=localhost;user=root;password=abc123;database=test;old guids=true;

注意旧的 guids=true 部分。

server=localhost;user=root;password=abc123;database=test;old guids=true;

Watch out old guids=true part.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文