![]() |
#2
sliang282016-02-03 10:47
异常的详细信息如下:
![]() 未处理System.AccessViolationException Message=尝试读取或写入受保护的内存。这通常指示其他内存已损坏。 Source=System.Data StackTrace: 在 System.(OdbcStatementHandle StatementHandle, Int16 ColumnNumber, Int16 FieldIdentifier, CNativeBuffer CharacterAttribute, Int16 BufferLength, Int16& StringLength, IntPtr& NumericAttribute) 在 System.Data.Odbc.OdbcStatementHandle.ColumnAttribute(Int32 columnNumber, Int16 fieldIdentifier, CNativeBuffer characterAttribute, Int16& stringLength, SQLLEN& numericAttribute) 在 System.Data.Odbc.OdbcDataReader.GetColAttributeStr(Int32 i, SQL_DESC v3FieldId, SQL_COLUMN v2FieldId, HANDLER handler) 在 System.Data.Odbc.OdbcDataReader.GetName(Int32 i) 在 System.Data.ProviderBase.SchemaMapping.GenerateFieldNames(DataReaderContainer dataReader) 在 System.Data.ProviderBase.SchemaMapping..ctor(DataAdapter adapter, DataSet dataset, DataTable datatable, DataReaderContainer dataReader, Boolean keyInfo, SchemaType schemaType, String sourceTableName, Boolean gettingData, DataColumn parentChapterColumn, Object parentChapterValue) 在 System.(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 schemaCount, DataColumn parentChapterColumn, Object parentChapterValue) 在 System.(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 schemaCount, DataColumn parentChapterColumn, Object parentChapterValue) 在 System.(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) 在 System.(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) 在 System.(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) 在 System.(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) 在 System.(DataTable dataTable) 在 WindowsFormsApplication1.Form1.txtLot_KeyPress(Object sender, KeyPressEventArgs e) 位置 c:\Users\1510014\Desktop\副本\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:行号 34 在 System.Windows.Forms.Control.OnKeyPress(KeyPressEventArgs e) 在 System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m) 在 System.Windows.Forms.Control.ProcessKeyMessage(Message& m) 在 System.Windows.Forms.Control.WmKeyChar(Message& m) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.TextBoxBase.WndProc(Message& m) 在 System.Windows.Forms.TextBox.WndProc(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 在 System.Windows.Forms.(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 在 System.Windows.Forms.Application.Run(Form mainForm) 在 WindowsFormsApplication1.Program.Main() 位置 c:\Users\1510014\Desktop\副本\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:行号 18 InnerException: |
下面函数可以正常调用2次,第三次调用的时候就出现了"尝试读取或写入受保护的内存"的错误,SQL语句只是换了变量而已,在数据库中sql多次查询都是正常的,请老师分析是什么问题造成的.谢谢!
OdbcCommand cmd = new OdbcCommand();
= commandText;
= type;
cmd.Connection = Conn;
OdbcDataAdapter dr = new OdbcDataAdapter(cmd);
DataTable dt = new DataTable();
dr.Fill(dt);
cmd.Connection.Close();
return dt;
= commandText;
= type;
cmd.Connection = Conn;
OdbcDataAdapter dr = new OdbcDataAdapter(cmd);
DataTable dt = new DataTable();
dr.Fill(dt);
cmd.Connection.Close();
return dt;