C# 使用C将xml加载到mysql#
我使用“加载本地xml”脚本将xml文件加载到带有C#的mysql数据库。 代码如下所示:C# 使用C将xml加载到mysql#,c#,mysql,xml,C#,Mysql,Xml,我使用“加载本地xml”脚本将xml文件加载到带有C#的mysql数据库。 代码如下所示: public void loadXML(string path, string table, string identify) { string query = "LOAD XML LOCAL INFILE "; query += "'"+path+"'"; query += " INTO TABLE " + table; query
public void loadXML(string path, string table, string identify)
{
string query = "LOAD XML LOCAL INFILE ";
query += "'"+path+"'";
query += " INTO TABLE " + table;
query += " Rows Identified By '<" + identify + ">';";
System.Diagnostics.Debug.Print(query);
if (this.OpenConnection() == true)
{
MySqlCommand cmd = new MySqlCommand(query, connection);
//Execute command
cmd.ExecuteNonQuery();
//close connection
this.CloseConnection();
}
}
public void loadXML(字符串路径、字符串表、字符串标识)
{
string query=“加载XML本地填充”;
查询+=“'”+路径+“'”;
查询+=“入表”+表;
查询+=“由“”标识的行;”;
系统.诊断.调试.打印(查询);
if(this.OpenConnection()==true)
{
MySqlCommand cmd=新的MySqlCommand(查询、连接);
//执行命令
cmd.ExecuteNonQuery();
//密切联系
这个.CloseConnection();
}
}
然而,我无法得到这项工作。我与VS 2015合作。
它给出了一个mysqlException:
“尝试读取结果集时遇到致命错误。”
InnerException是找不到该文件,这很奇怪,因为该文件肯定不是我的目标文件
此处显示调试输出:
Exception thrown: 'MySql.Data.MySqlClient.MySqlException' in MySql.Data.dll
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>ConsoleApplication1.vshost.exe</AppDomain> <Exception><ExceptionType>MySql.Data.MySqlClient.MySqlException, MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d</ExceptionType><Message>Fatal error encountered attempting to read the resultset.</Message><StackTrace> at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at ConsoleApplication1.DBConnect.loadXML() in C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\DBConnect.cs:line 124
at ConsoleApplication1.Program.Main() in C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\Program.cs:line 47
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()</StackTrace><ExceptionString>MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered attempting to read the resultset. ---&gt; MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered attempting to read the resultset. ---&gt; MySql.Data.MySqlClient.MySqlException (0x80004005): Error during LOAD DATA LOCAL INFILE ---&gt; System.IO.FileNotFoundException: Could not find file 'C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\bin\Debug\UsersLuDesktopperson.xml'.
File name: 'C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\bin\Debug\UsersLuDesktopperson.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at MySql.Data.MySqlClient.NativeDriver.SendFileToServer(String filename)
at MySql.Data.MySqlClient.NativeDriver.SendFileToServer(String filename)
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&amp; affectedRow, Int64&amp; insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32&amp; affectedRows, Int64&amp; insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at ConsoleApplication1.DBConnect.loadXML() in C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\DBConnect.cs:line 124
at ConsoleApplication1.Program.Main() in C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\Program.cs:line 47
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()</ExceptionString><InnerException><ExceptionType>MySql.Data.MySqlClient.MySqlException, MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d</ExceptionType><Message>Fatal error encountered attempting to read the resultset.</Message><StackTrace> at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)</StackTrace><ExceptionString>MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered attempting to read the resultset. ---&gt; MySql.Data.MySqlClient.MySqlException (0x80004005): Error during LOAD DATA LOCAL INFILE ---&gt; System.IO.FileNotFoundException: Could not find file 'C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\bin\Debug\UsersLuDesktopperson.xml'.
File name: 'C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\bin\Debug\UsersLuDesktopperson.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at MySql.Data.MySqlClient.NativeDriver.SendFileToServer(String filename)
at MySql.Data.MySqlClient.NativeDriver.SendFileToServer(String filename)
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&amp; affectedRow, Int64&amp; insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32&amp; affectedRows, Int64&amp; insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)</ExceptionString><InnerException><ExceptionType>MySql.Data.MySqlClient.MySqlException, MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d</ExceptionType><Message>Error during LOAD DATA LOCAL INFILE</Message><StackTrace> at MySql.Data.MySqlClient.NativeDriver.SendFileToServer(String filename)
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&amp; affectedRow, Int64&amp; insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32&amp; affectedRows, Int64&amp; insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()</StackTrace><ExceptionString>MySql.Data.MySqlClient.MySqlException (0x80004005): Error during LOAD DATA LOCAL INFILE ---&gt; System.IO.FileNotFoundException: Could not find file 'C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\bin\Debug\UsersLuDesktopperson.xml'.
File name: 'C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\bin\Debug\UsersLuDesktopperson.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at MySql.Data.MySqlClient.NativeDriver.SendFileToServer(String filename)
at MySql.Data.MySqlClient.NativeDriver.SendFileToServer(String filename)
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&amp; affectedRow, Int64&amp; insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32&amp; affectedRows, Int64&amp; insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()</ExceptionString><InnerException><ExceptionType>System.IO.FileNotFoundException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Could not find file 'C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\bin\Debug\UsersLuDesktopperson.xml'.</Message><StackTrace> at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at MySql.Data.MySqlClient.NativeDriver.SendFileToServer(String filename)</StackTrace><ExceptionString>System.IO.FileNotFoundException: Could not find file 'C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\bin\Debug\UsersLuDesktopperson.xml'.
File name: 'C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\bin\Debug\UsersLuDesktopperson.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at MySql.Data.MySqlClient.NativeDriver.SendFileToServer(String filename)</ExceptionString></InnerException></InnerException></InnerException></Exception></TraceRecord>
在MySql.Data.dll中引发异常:“MySql.Data.MySqlClient.MySqlException”
系统。关键事务:0:http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionConsoleApplication1.vshost.exe MySql.Data.MySqlClient.MySqlException,MySql.Data,版本=6.9.8.0,区域性=中性,PublicKeyToken=C5687FC88969C44尝试读取结果集时遇到致命错误。位于MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior)
在MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()处
在C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\DBConnect.cs中的ConsoleApplication1.DBConnect.loadXML()处:第124行
在C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\Program.cs中的ConsoleApplication1.Program.Main()处:第47行
位于System.AppDomain.\u nExecuteAssembly(RuntimeAssembly程序集,字符串[]args)
位于System.AppDomain.ExecuteAssembly(字符串汇编文件、证据汇编安全性、字符串[]args)
在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()上
位于System.Threading.ThreadHelper.ThreadStart\u上下文(对象状态)
位于System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext、ContextCallback回调、对象状态、布尔值preserveSyncCtx)
在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔保存SyncCTX)
在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态)
在System.Threading.ThreadHelper.ThreadStart()MySql.Data.MySqlClient.MySqlException(0x80004005)处:尝试读取结果集时遇到致命错误---&;燃气轮机;MySql.Data.MySqlClient.MySqlException(0x80004005):尝试读取结果集时遇到致命错误---&;燃气轮机;MySql.Data.MySqlClient.MySqlException(0x80004005):加载数据本地填充时出错---&;燃气轮机;System.IO.FileNotFoundException:找不到文件“C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\bin\Debug\usersluedesktopperson.xml”。
文件名:“C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\bin\Debug\usersluedesktopperson.xml”
在System.IO.\uuu Error.WinIOError(Int32 errorCode,字符串maybeFullPath)
在System.IO.FileStream.Init(字符串路径、文件模式、文件访问权限、Int32权限、布尔用户权限、文件共享、Int32缓冲大小、文件选项选项、安全属性secAttrs、字符串msgPath、布尔bFromProxy、布尔useLongPath、布尔checkHost)
位于System.IO.FileStream..ctor(字符串路径、文件模式、文件访问)
位于MySql.Data.MySqlClient.NativeDriver.SendFileToServer(字符串文件名)
位于MySql.Data.MySqlClient.NativeDriver.SendFileToServer(字符串文件名)
位于MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&;affectedRow、Int64&;insertedId)
位于MySql.Data.MySqlClient.Driver.GetResult(Int32语句ID、Int32和affectedRows、Int64和insertedId)
位于MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId,Boolean force)
在MySql.Data.MySqlClient.MySqlDataReader.NextResult()中
在MySql.Data.MySqlClient.MySqlDataReader.NextResult()中
位于MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior)
位于MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior)
在MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()处
在C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\DBConnect.cs中的ConsoleApplication1.DBConnect.loadXML()处:第124行
在C:\Users\Lu\Google Drive\Capstone\CMPUT701\Project Codes\ConsoleApplication1\ConsoleApplication1\Program.cs中的ConsoleApplication1.Program.Main()处:第47行
位于System.AppDomain.\u nExecuteAssembly(RuntimeAssembly程序集,字符串[]args)
位于System.AppDomain.ExecuteAssembly(字符串汇编文件、证据汇编安全性、字符串[]args)
在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()上
位于System.Threading.ThreadHelper.ThreadStart\u上下文(对象状态)
位于System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext、ContextCallback回调、对象状态、布尔值preserveSyncCtx)
在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔保存SyncCTX)
在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态)
在System.Threading.ThreadHelper.ThreadStart()MySql.Data.MySqlClient.MySqlException,MySql.Data,版本=6.9.8.0,区域性=中立,PublicKeyToken=C5687FC88969C44D尝试读取结果集时遇到致命错误。在MySql.Data.MySqlClient.MySqlDataReader.NextResult()中
在MySql.Data.MySqlClient上。
public void loadXML(string path, string table, string identify)
{
var con = new Connection(ConnectionString)
string query = "LOAD XML LOCAL INFILE ";
query += "'"+path+"'";
query += " INTO TABLE " + table;
query += " Rows Identified By '<" + identify + ">';";
System.Diagnostics.Debug.Print(query);
if (this.OpenConnection() == true)
{
MySqlCommand cmd = new MySqlCommand(query,con );
//Execute command
cmd.ExecuteNonQuery();
//close connection
this.CloseConnection();
}
}