.NET Questions and Solutions

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘System’

Error when you try to call the Prepare method before you add parameters: “An unhandled exception of type ‘System.Data.SqlClient.SqlException’ occurred in system.data.dll”

Symptoms
When you create a parameterized command against Microsoft SQL Server 7.0, if you call the Prepare method before you add parameters to the command, you receive the following error message:

An unhandled exception of type ‘System.Data.SqlClient.SqlException’ occurred in system.data.dll.
Additional information: System error. This problem does not occur in SQL Server 2000.
Resolution
This problem occurs in SQL Server 7.0 because, by design, you cannot run the Prepare method before you add parameters. This applies to most database systems.
SQL Server 2000 does not generate the above-mentioned exception because it does not run Prepare until the first command is executed. This optimization prevents the overhead of Prepare if no commands are subsequently executed.

Error message when you use the binaries from the SQL Server System CLR Types package (SQLSysClrTypes.msi): “Unable to load DLL ‘SqlServerSpatial.dll’: This application has failed to start because …

Symptoms
After you install the SQL Server System CLR Types package (SQLSysClrTypes.msi), you receive the following error message when you try to use the binaries that this package installs:

Unable to load DLL ‘SqlServerSpatial.dll’: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0×800736B1)Additionally, the following information is logged in the event log:
EventID: 32
Description: Dependent Assembly Microsoft.VC80.CRT could not be found and Last Error was The referenced assembly is not installed on your system.
EventID: 59
Description: Resolve Partial Assembly failed for Microsoft.VC80.CRT. Reference error message: The referenced assembly is not installed on your system.
EventID: 59
Description: Generate Activation Context failed for C:\WINDOWS\system32\SqlServerSpatial.dll. Reference error message: The operation completed successfully.
Resolution
This problem occurs because the C Run-Time (CRT) library is not installed. The binary files in the SQL Server System CLR Types package rely on the CRT library.
Note The CRT library is included in the Microsoft Visual C++ 2008 Redistributable Package.

Error message when you upgrade to Microsoft Dynamics CRM 4.0: “Exception has been thrown by the target of an invocation”

Symptoms
When you upgrade to Microsoft Dynamics CRM 4.0, the upgrade process cannot be completed. Additionally, you receive the following error message in the CRM40setup.log file:

Time|Info| Updating precision and scale of decimal attributes
Time|Error| System.Exception: Action
Microsoft.Crm.Setup.Server.InstallDatabaseAction failed. —>
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Data.SqlClient.SqlException: The statistics ‘hind_1090102924_1A_2A_4A_9A_15A’ is dependent on column ‘Quantity’.
ALTER TABLE ALTER COLUMN Quantity failed because one or more objects access this column.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.Crm.CrmDbConnection.InternalExecuteNonQuery(IDbCommand command)
at Microsoft.Crm.CrmDbConnection.ExecuteNonQuery(IDbCommand command, Boolean impersonate)
at Microsoft.Crm.CrmDbConnection.ExecuteNonQuery(IDbCommand command)
at Microsoft.Crm.Setup.DiffBuilder.UpdatePrecisionAndScaleOnDecimalAttributes()
— End of inner exception stack trace —
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.Crm.Setup.Database.DllMethodAction.Execute()
at Microsoft.Crm.Setup.Database.DatabaseInstaller.ExecuteReleases(ReleaseCollection releases, Int32 currentProgress)
at Microsoft.Crm.Setup.Database.DatabaseInstaller.installInternal()
at Microsoft.Crm.Setup.Database.DatabaseInstaller.Install(Int32 languageCode, String configurationFilePath, Boolean upgradeDatabase)
at Microsoft.Crm.Setup.Server.InstallDatabaseAction.Do(IDictionary parameters)
at Microsoft.Crm.Setup.Common.Action.ExecuteAction(Action action, IDictionary parameters, Boolean undo)
— End of inner exception stack trace —, Error, RetryCancel, Option1Note By default, the CRM40setup.log file is in the following folder:
C:\Documents and Settings\upgrading user\Application Data\Microsoft\MSCRM\logs
This problem occurs if you have custom statistics in the OrgName_MSCRM database.
Resolution
This problem occurs because the upgrade process cannot handle custom statistics in the OrgName_MSCRM database.

Error message when you update a database by using a stored procedure: “System.Data.DBConcurrencyException”

Symptoms
When you use a DataAdapter object to write changes back to a database by means of a stored procedure, you may receive the following error message:

An unhandled exception of type ‘System.Data.DBConcurrencyException’ occurred in system.data.dll
Additional information: Concurrency violation: the UpdateCommand affected 0 records. If the data is not updated correctly, you should receive a DataConcurrencyException exception instead of the above-mentioned error message.
Resolution
This problem can occur if the stored procedure runs the SET NOCOUNT ON statement.

Error message when you try to use the Microsoft Exchange Server ActiveSync Web Administration tool to delete a partnership or to perform a Remote Wipe operation on a mobile device in Exchange Ser …

Symptoms
When you try to use the Microsoft Exchange Server ActiveSync Web Administration tool to delete a partnership with a mobile device or to perform a Remote Wipe operation on a mobile device, you receive the following error message:

Failed to access user’s Mailbox, verify that the mailbox and user account are enabled and functional.
Server Error in ‘/MobileAdmin’ Application.
——————————————————————————–
The remote server returned an error: (401) Unauthorized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[WebException: The remote server returned an error: (401) Unauthorized.]
System.Net.HttpWebRequest.CheckFinalStatus() +680
System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult) +74
System.Net.HttpWebRequest.GetRequestStream() +234
Microsoft.Exchange.AirSync.Admin.Mailbox.propFindRequest(String deviceUri) +240
Microsoft.Exchange.AirSync.Admin.Mailbox.getDevices() +194
Microsoft.Exchange.AirSync.Admin.Devices.refreshDevicesTable() +135
Microsoft.Exchange.AirSync.Admin.Devices.Page_Load(Object sender, EventArgs e) +190
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
——————————————————————————–
Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET Version:1.1.4322.2300
Resolution
This issue occurs if one or both of the following conditions are true:Integrated Windows authentication is not enabled on the Exadmin virtual directory on the mailbox server.
Note In a front-end/back-end (FE/BE) Exchange configuration, this issue occurs if Integrated Windows authentication is not enabled on the Exadmin virtual directory on the back-end server.The MobileAdmin Web application is not running under the ExchangeApplicationPool application pool.

BUG: You receive a security exception error message when you call the EventLog.WriteEntry method by using the EventLogPermissionAccess.Write access level in the .NET Framework 2.0

Symptoms
Consider the following scenario. In the Microsoft .NET Framework 2.0, you create an instance of the EventLogPermission class that has the EventLogPermissionAccess.Write access level. You call the EventLogPermission.PermitOnly method to restrict code access. Then you call the EventLog.WriteEntry method to write an entry to the event log. In this scenario,you receive a security exception error message that resembles the following:

Unhandled Exception: System.Security.SecurityException: Request for the permission of type ‘System.Diagnostics.EventLogPermission, …’ failed.
Resolution
To work around this issue, you must request the EventLogPermissionAccess.Administer access level before you call the EventLogPermission.PermitOnly method. After you specify this access level, you can call the EventLog.WriteEntry method and write an entry to the event log. The following code example demonstrates how to write an entry to the event log by using this workaround.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

using System;using System.Diagnostics;public class TestCase{ public static void Main() { EventLogPermission eventLogPermission = new EventLogPermission(EventLogPermissionAccess.Administer, “.”); eventLogPermission.PermitOnly(); EventLog.WriteEntry(“Source”, “Message”); }}