I think I am having a problem with my sql database. I have an application that is all of a sudden throwing an access violation error when ever the tableadapter is filled.
I believe that something may have happened to the database in general because if I pull up an earlier version of the program code, I get the same errors.
This is the line that it fails during
URTableAdapter.Fill(URDataSet.UR)
This is the Exception error text:
Exception thrown: 'System.Data.ConstraintException' in System.Data.dll
System.Transactions Critical: 0 : xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" >Severity="Critical"
TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/200>4/07/Reliability/Exception/UnhandledUnhandled >exceptionUR.vshost.exe>>
System.Data.ConstraintException, System.Data, Version=4.0.0.0, >Culture=neutral, PublicKeyToken=b77a5c561934e089Failed >to enable constraints. One or more rows contain values violating non-null, >unique, or foreign-key constraints. at >System.Data.DataSet.EnableConstraints()
at System.Data.DataSet.set_EnforceConstraints(Boolean value)
at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader >dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, >DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, >IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 >startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at UR.URDataSetTableAdapters.URTableAdapter.Fill(URDataTable dataTable) in >H:\Databases\UR\UREvolv\UR\URDataSet.Designer.vb:line 10650
at UR.DataEntry.LOCCB_SelectedIndexChanged(Object sender, EventArgs e) in >H:\Databases\UR\UREvolv\UR\DataEntry.vb:line 2103
at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 >msg, IntPtr wparam, IntPtr lparam)>System.Data.ConstraintException: Failed to enable constraints. >One or more rows contain values violating non-null, unique, or foreign-key >constraints.
at System.Data.DataSet.EnableConstraints()
at System.Data.DataSet.set_EnforceConstraints(Boolean value)
at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader >dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, >DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, >IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 >startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at UR.URDataSetTableAdapters.URTableAdapter.Fill(URDataTable dataTable) in >H:\Databases\UR\UREvolv\UR\URDataSet.Designer.vb:line 10650
at UR.DataEntry.LOCCB_SelectedIndexChanged(Object sender, EventArgs e) in >H:\Databases\UR\UREvolv\UR\DataEntry.vb:line 2103
at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 >msg, IntPtr wparam, IntPtr lparam)
The program '[13508] UR.vshost.exe' has exited with code -1073741819 >(0xc0000005) 'Access violation'.
Thank you for any help you may be able to give,
Steve
I am still not sure what happened to the original exe and DB, but I was able to restore an older copy of the program with a current backup of the DB and make the changes since previous version.
Thank you,
Steve
Related
I have this code in my application:
My.Computer.FileSystem.CopyFile("D:\Temp\Origin.log", "D:\Temp\Destination.log", True)
This code used to work fine until 1 or 2 months ago.
The last couple of months it fails to execute and it throws a 'System.IO.IOException' in mscorlib.dll "Unsupported" when the destination files exists.
My target framework is 4.7.2
I tried to change target framework to 4.6.2 in case an update of NET framework broke it, but still I have the same issue.
Right now I had to temporarily bypass the problem like this:
If My.Computer.FileSystem.FileExists("D:\Temp\Destination.log") Then
My.Computer.FileSystem.DeleteFile("D:\Temp\Destination.log", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
End If
My.Computer.FileSystem.CopyFile("D:\Temp\Origin.log", "D:\Temp\Destination.log", True)
While the above code works, it defeats the purpose of having an overwrite overload (which is still supported in 4.7.2 AFAIK)
Also it means I have to change it in far too many places inside my application code.
Does anyone knows why my original code stopped working, or better yet, how to fix it ?
Edit:
Exception Stack:
System.IO.IOException
HResult=0x80070032
Message=The request is not supported.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at Microsoft.VisualBasic.FileIO.FileSystem.CopyOrMoveFile(CopyOrMove operation, String sourceFileName, String destinationFileName, Boolean overwrite, UIOptionInternal showUI, UICancelOption onUserCancel)
at Microsoft.VisualBasic.MyServices.FileSystemProxy.CopyFile(String sourceFileName, String destinationFileName, Boolean overwrite)
at KT_Scan_Docs_Manager.Frm_Main.CreateFilelist(Int32 Meleti) in C:\Users\GTsag\Dropbox\Visual Studio\KT2-14 Scan Docs Manager\KT2-14 Scan Docs Manager\frm_Main.vb:line 2880
at KT_Scan_Docs_Manager.Frm_Main.Bt_KT214CreateFileList_Click(Object sender, EventArgs e) in C:\Users\GTsag\Dropbox\Visual Studio\KT2-14 Scan Docs Manager\KT2-14 Scan Docs Manager\frm_Main.vb:line 148
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at KT_Scan_Docs_Manager.My.MyApplication.Main(String[] Args) in :line 81
I'm new to this site and I'm going to start immediately with a question.
Currently I'm working on a thesis but I'm a stuck at this moment. I've been asked to control an IP-camera via Beckhoff Twincat3. As this is based on visual studio, I thought it might be a good idea to start in visual basic to test and debug everything I code. Everything I do results in AccessViolation.
System.AccessViolationException was unhandled
HResult=-2147467261
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=mscorlib
StackTrace:
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at RASplus_WatSearLib._DRASplus_WatSear.setCameraMap(Int16 nCamNum, Int16 postKey, String szSiteName, String szAddr, Int16 nHostCam, String szUser, String szPasswd, Int16 port, Boolean mode, Boolean bUseModem, Boolean useDvrns, String szDvrnsAddr, Int16 dvrnsPort, Int16 audioPort)
at AxRASplus_WatSearLib.AxRASplus_WatSear.setCameraMap(Int16 nCamNum, Int16 postKey, String szSiteName, String szAddr, Int16 nHostCam, String szUser, String szPasswd, Int16 port, Boolean mode, Boolean bUseModem, Boolean useDvrns, String szDvrnsAddr, Int16 dvrnsPort, Int16 audioPort)
at activex_camera.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\BECKHOFF stage\documents\visual studio 2010\Projects\activex camera\activex camera\Form1.vb:line 41
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at activex_camera.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
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()
InnerException:
I'm currently trying to connect with the camera and it results each time in a AccessViolation.
myCam.setCameraMap(i, CShort(0), "10.199.217.144", "10.199.217.144", i, "admin", "", CShort(8016), False, False, False, "dvrnames.net", 10088, 8116)
I hope someone can get me back on track. If .ocx or other files needed, please do not hesitate to contact me.
I asked my teacher if he knew what was wrong and he came up with this :
In the program, I was working with an 'instance' of the activex-control. This resulted in a accessviolation. He fixed it by using the direct control.
After all it made sense. ;)
Sincerely
GiovanniVanAssche
I am building a VB.NET desktop application in VS2013 that uses a .mdf file created in SQL Server 2012. I have the .mdf file imported in to the application. Along with the datagridviews I am using to view/modify the database tables I need to execute a SQL script when the user clicks on a button.
I have been trying several examples I've found, without any luck. I'm getting a FileLoadException error on the ExecuteNonQuery line:
An unhandled exception of type 'System.IO.FileLoadException' occurred
in mscorlib.dll
Additional information: Mixed mode assembly is built against version
'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime
without additional configuration information.
The "Troubleshooting tips" section has "Make sure that the file is a valid .NET Framework assembly". I clicked on that link, but the information there isn't very helpful to me, as I really am not understanding what it's saying.
I've tried these two examples so far:
Dim sqlScript As String = "C:\HL_Time_Entry_Reporting\SQL Scripts\stage_employee_hours_load.sql"
Dim connString As String = "Server=(LocalDB)\v11.0;Integrated Security=True;AttachDbFilename=C:\HL_Time_Entry_Reporting\Database\hours_analysis.mdf"
Dim connectionString As String = connString,
scriptText As String = sqlScript
Dim sqlConnection As New SqlConnection(connectionString)
Dim svrConnection As New ServerConnection(sqlConnection)
Dim server As New Server(svrConnection)
server.ConnectionContext.ExecuteNonQuery(scriptText)
from this site. And
Dim sqlConnectionString As String = "Server=(LocalDB)\v11.0;Integrated Security=True;AttachDbFilename=C:\HL_Time_Entry_Reporting\Database\hours_analysis.mdf"
Dim file As New FileInfo("C:\HL_Time_Entry_Reporting\SQL Scripts\stage_employee_hours_load.sql")
Dim script As String = file.OpenText().ReadToEnd()
Dim conn As New SqlConnection(sqlConnectionString)
Dim server As New Server(New ServerConnection(conn))
server.ConnectionContext.ExecuteNonQuery(script)
from this site.
One thing is, I'm not confident I have the correct connection string for this. That's the connection string I have for the datagridviews, which works fine, but is that also what I should use to connect for the sql script file as well?
UPDATE
Per request, here is the stack trace:
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly
assembly, String name, Boolean throwOnError, Boolean ignoreCase,
ObjectHandleOnStack type) at
System.Reflection.RuntimeAssembly.GetType(String name, Boolean
throwOnError, Boolean ignoreCase) at
System.Reflection.Assembly.GetType(String name, Boolean throwOnError)
at
Microsoft.SqlServer.Management.Common.ServerConnection.GetStatements(String
query, ExecutionTypes executionType, Int32& statementsToReverse) at
Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String
sqlCommand, ExecutionTypes executionType) at
Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String
sqlCommand) at test.main.btnLoadMasterData_Click(Object sender,
EventArgs e) in C:\Users\marky\Documents\Visual Studio
2013\Projects\Hours Analysis\Hours Analysis\Form1.vb:line 212 at
System.Windows.Forms.Control.OnClick(EventArgs e) at
System.Windows.Forms.Button.OnClick(EventArgs e) at
System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at
System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks) at
System.Windows.Forms.Control.WndProc(Message& m) at
System.Windows.Forms.ButtonBase.WndProc(Message& m) at
System.Windows.Forms.Button.WndProc(Message& m) at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr
dwComponentID, Int32 reason, Int32 pvLoopData) at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context) at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context) at
System.Windows.Forms.Application.Run(ApplicationContext context) at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine) at test.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 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()
UPDATE #2
As suggested, I added the startup tag in this SO question to my appconfig file but got a new error on the line "Dim server As New Server(New ServerConnection(conn))" in the second code example. It's a TypeInitializationException. Here's the info:
An unhandled exception of type 'System.TypeInitializationException'
occurred in System.Data.dll
Additional information: The type initializer for
'System.Data.SqlClient.SqlConnection' threw an exception.
Stack trace:
at System.Data.SqlClient.SqlConnection..ctor() at
System.Data.SqlClient.SqlConnection..ctor(String connectionString,
SqlCredential credential) at
System.Data.SqlClient.SqlConnection..ctor(String connectionString)
at test.main.btnLoadMasterData_Click(Object sender, EventArgs e) in
C:\Users\marky\Documents\Visual Studio 2013\Projects\Hours
Analysis\Hours Analysis\Form1.vb:line 210 at
System.Windows.Forms.Control.OnClick(EventArgs e) at
System.Windows.Forms.Button.OnClick(EventArgs e) at
System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at
System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks) at
System.Windows.Forms.Control.WndProc(Message& m) at
System.Windows.Forms.ButtonBase.WndProc(Message& m) at
System.Windows.Forms.Button.WndProc(Message& m) at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr
dwComponentID, Int32 reason, Int32 pvLoopData) at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context) at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context) at
System.Windows.Forms.Application.Run(ApplicationContext context) at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine) at test.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 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()
It looks like you may be using an obsolete version of the SMO library, as explained here: https://stackoverflow.com/a/11286124/109122.
Update:
If the config setting recommended at the link does not work, try this simpler one instead:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
Unfortunately, it appears that the config file changes do not fix all cases.
In the past couple of weeks my client's customers have been receiving the error below when running any sort of query on their website. I am not proficient with SQL, so any help would be appreciated.
Stack Trace:
[SqlException (0x80131904): Arithmetic overflow error converting
numeric to data type numeric.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection) +1951066
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) +4847051
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj) +194 System.Data.SqlClient.TdsParser.Run(RunBehavior
runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj) +2392 System.Data.SqlClient.SqlDataReader.HasMoreRows()
+157 System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout) +197 System.Data.SqlClient.SqlDataReader.Read() +9
System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
+78 System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader,
Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn,
Object parentChapterValue) +164
System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable,
IDataReader dataReader, Int32 startRecord, Int32 maxRecords) +353
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior) +164
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior) +287
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable) +92
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments
arguments) +1297 System.Web.UI.WebControls.Repeater.GetData() +35
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean
useDataSource) +220
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +51
System.Web.UI.WebControls.Repeater.DataBind() +75
System.Web.UI.WebControls.Repeater.EnsureDataBound() +55
System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +15
System.Web.UI.Control.PreRenderRecursiveInternal() +80
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+842
The places to look are either:
There is an update query that is trying to change an int (or some other small number datatype) with a larger number datatype (like a single or a double).
It is trying an isert with the same conditions.
Focus on looking for something changing values with numeric fields and check to see what datatypes are trying to make those changes. When you see a mismatch, that is most likely your culprit.
change sum(col1) to sum(cast(col1 as bigint)) to change the current column's type dynamically or change it in the table design mode.
I've a data grid gridDetails with columns discount and total filled from the database
Total is readonly while discount is not. When the value of discount is changed, The total is recalculated as
gridDetails.Item(1, e.RowIndex).Value -= (Val(gridDetails.Item(2, e.RowIndex).Value))
after changing the value the column cant be sorted. it generates an exception
System.ArgumentException was unhandled
Message="Object must be of type Double."
Source="mscorlib"
StackTrace:
at System.Double.CompareTo(Object value)
at System.Collections.Comparer.Compare(Object a, Object b)
at System.Windows.Forms.DataGridViewRowCollection.RowComparer.CompareObjects(Object value1, Object value2, Int32 rowIndex1, Int32 rowIndex2)
at System.Windows.Forms.DataGridViewRowCollection.RowArrayList.Pivot(Int32 left, Int32 center, Int32 right)
at System.Windows.Forms.DataGridViewRowCollection.RowArrayList.CustomQuickSort(Int32 left, Int32 right)
at System.Windows.Forms.DataGridViewRowCollection.RowArrayList.CustomSort(RowComparer rowComparer)
at System.Windows.Forms.DataGridViewRowCollection.Sort(IComparer customComparer, Boolean ascending)
at System.Windows.Forms.DataGridView.SortInternal(IComparer comparer, DataGridViewColumn dataGridViewColumn, ListSortDirection direction)
at System.Windows.Forms.DataGridView.Sort(DataGridViewColumn dataGridViewColumn, ListSortDirection direction)
at System.Windows.Forms.DataGridView.OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e)
at System.Windows.Forms.DataGridView.OnMouseClick(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at cableguy.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly 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.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
i've converted the result to double using Cdbl, DirectCast etc.. no hope
like
gridDetails.Item(1, e.RowIndex).Value = Cdbl(gridDetails.Item(1, e.RowIndex).Value-Val(gridDetails.Item(2, e.RowIndex).Value))
any idea??
Right, this is what I think is happening.
When you load the data from the database it is displayed as strings in the table. This way it's sortable and everything is fine. Then you go and change a value with your subtraction (quite possibly the first row). This alters the sorting to become based on doubles instead. Since your entire table is displayed with strings it crashes.
So basically, eiter make really sure that you insert doubles into your Datagridview from the beginning, convert the all the values in the column after you loaded your table or insert the updated value as a string.
if you are adding doubles, decimals, etc. to a gridview and you need to add a zero where there is no value be sure to use Ctype:
If IsNumeric(drs.Item("qty")) then
dgvX.row(I).cell(0).value = CType(drs.Item("qty"), decimal)
Else
dgvX.row(I).cell(0).value = CType(0, decimal)
End If
what #WozzeC explained is the reason... am adding wht i've done to make it alright.. Before adding to grid i've converted the values to Double. Now its okei.. :) :happy:
read the data to a datareader and
While data.Read = True
Dim total_amount As Double = data("discount")
Dim discount_amount As Double = data("total")
gridDetails.Rows.Add(total_amount ,discount_amount)
End While
foreach(DataGridViewRow rowV in gridVerifyedData.Rows)
{
rowV.Cells["Tot_Work_hours"].Value = Convert.ToDouble(rowV.Cells["Tot_Work_hours"].Value);
}
gridVerifyedData.Sort(gridVerifyedData.Columns["Tot_Work_hours"], ListSortDirection.Descending);