MySqlCommand.ExecuteReader()在初始化时引发System.Format异常 [英] MySqlCommand.ExecuteReader() is throwing a System.Format exception on Initialization
问题描述
因此,我试图使用MySqlDataReader从数据库中获取数据.我知道数据库确实可以响应(从我的程序中正常插入,删除和更新所有工作).
So I'm trying to use a MySqlDataReader to acquire data from my database. I know that the database does in fact respond (insert, delete, and update all work fine from my program).
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
// Open a connection
conn.Open();
MySqlCommand command = conn.CreateCommand();
command.CommandText = "select * from cs3500_u0848199.PairedGames";
// Execute the command and cycle through the DataReader object
using (MySqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{ /*do something here*/}
}
}
问题似乎并不出在命令本身上,因为该命令在MySQL工作台中有效.无论如何,在执行这一行代码后
The problem does not appear to be with the command itself, as the command works in the MySQL workbench. Anyways, upon executing this line of code
using (MySqlConnection conn = new MySqlConnection(connectionString))
VS调试器注意到抛出了以下异常
the VS debugger notes that the following exception was thrown
System.FormatException由用户代码未处理
HResult = -2146233033消息=向导应包含32位数字和4 破折号(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).来源= mscorlib
堆栈跟踪: 在System.Guid.TryParseGuidWithNoStyle(String guidString,GuidResult& result)处 在System.Guid.TryParseGuid(字符串g,GuidStyles标志,GuidResult&结果) 在System.Guid..ctor(字符串g) 在MySql.Data.Types.MySqlGuid.MySql.Data.Types.IMySqlValue.ReadValue(MySqlPacket 数据包,Int64长度,布尔值nullVal) 在MySql.Data.MySqlClient.NativeDriver.ReadColumnValue(Int32索引,MySqlField字段,IMySqlValue valObject) 在MySql.Data.MySqlClient.Driver.ReadColumnValue(Int32索引,MySqlField字段,IMySqlValue值) 在MySql.Data.MySqlClient.ResultSet.ReadColumnData(Boolean outputParms) 在MySql.Data.MySqlClient.ResultSet.NextRow(CommandBehavior行为) 在MySql.Data.MySqlClient.MySqlDataReader.Read() 在d:\ repositories \ x0848199 \ PS11 \ ToDoService \ BoggleService.svc.cs:line中的ToDoList.BoggleService.GetBriefStatus(String gameToken) 443 在SyncInvokeGetBriefStatus(Object,Object [],Object []) 在System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object 实例,Object []输入,Object []&输出) 在System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)InnerException:
System.FormatException was unhandled by user code
HResult=-2146233033 Message=Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). Source=mscorlib
StackTrace: at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult& result) at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result) at System.Guid..ctor(String g) at MySql.Data.Types.MySqlGuid.MySql.Data.Types.IMySqlValue.ReadValue(MySqlPacket packet, Int64 length, Boolean nullVal) at MySql.Data.MySqlClient.NativeDriver.ReadColumnValue(Int32 index, MySqlField field, IMySqlValue valObject) at MySql.Data.MySqlClient.Driver.ReadColumnValue(Int32 index, MySqlField field, IMySqlValue value) at MySql.Data.MySqlClient.ResultSet.ReadColumnData(Boolean outputParms) at MySql.Data.MySqlClient.ResultSet.NextRow(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlDataReader.Read() at ToDoList.BoggleService.GetBriefStatus(String gameToken) in d:\repositories\x0848199\PS11\ToDoService\BoggleService.svc.cs:line 443 at SyncInvokeGetBriefStatus(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) InnerException:
由于我在此代码中未使用Guid,因此真的不确定为什么会告诉我有关Guid格式的信息. 任何帮助将不胜感激.
Really unsure as to why it's telling me about the guid format since i'm not using Guids in this code. Any help will be greatly appreciated.
推荐答案
看来,将;old guids=true;
附加到连接字符串可以解决此问题.
it appears that appending ;old guids=true;
to the connection string resolved the issue.
这篇关于MySqlCommand.ExecuteReader()在初始化时引发System.Format异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!