Showing posts with label .NET Errors and Solutions. Show all posts
Showing posts with label .NET Errors and Solutions. Show all posts

Tuesday, June 4, 2019

Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine

Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine


Error:

The error message Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine is thrown when I tried accessing the Excel file using OLEDB connection.



The issue I described in my scenario occurred basically due to the incompatibility of the Microsoft.Jet.OLEDB.4.0 driver in 64 bit OS.

Solution:

So if we are using Microsoft.Jet.OLEDB.4.0 driver in a 64 bit server, we have to force our application to build in in 32 bit mode(change the build property of the project to X86) and that causes other part of my code to break.

Fortunately, now Microsoft has released a 64 bit compatible 2010 Office System Driver which can be used as replacement for the traditional Microsoft.Jet.OLEDB.4.0 driver. It works both in 32 bit as well as 64 bit servers. I have used it for Excel file manipulation and it worked fine for me in both the environments.

You can download this driver from Microsoft Access Database Engine 2010 Redistributable - 64-bit compatible 2010 office system driver

If the file extension is xls and OS is 32 bit then only you can use "Microsoft.Jet.OLEDB.4.0". Microsoft has not released 64 bit version of this driver.

If file extension is xlsx or OS is 64 bit then you must have to use "Microsoft.ACE.OLEDB.12.0". The application compiled in 32/64 bit mode does not impact the selection of driver.

Always install the 64 bit driver of Microsoft.ACE.OLEDB.12.0 on OS 64 bit. If you have already installed Office 32 bit then you need to run driver from cmd with /passive argument. This hack works till Office 2013 only, Microsoft stopped this workaround from Office 2016 for Microsoft.ACE.OLEDB.16.0 drivers.


private void ProcessFile(string path)
{
    string connString = string.Empty;

    if (Path.GetExtension(path).ToLower().Trim() == ".xls" && Environment.Is64BitOperatingSystem == false)
        connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
    else
        connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}



There is indeed no 64 bit version of Jet - and no plans (apparently) to produce one.



Wednesday, January 25, 2017

Telerik ASP.NET Ajax client-side framework failed to load

Telerik;0x800a139e - JavaScript runtime error: ASP.NET Ajax client-side framework failed to load;0x800a1391 - JavaScript runtime error: 'Sys' is undefined

For Internet Explorer users getting the following error:


Problem:

Recently I encountered an issue, RadScriptManager started throwing the following errors:

0x800a139e - JavaScript runtime error: ASP.NET Ajax client-side framework failed to load.

0x800a1391 - JavaScript runtime error: 'Sys' is undefined


This issue is observed on IE 11 and doesn't appear on Chrome or Firefox Browsers.

Suggested solution:


I had below in my web.config. I removed runtimeversion2.0 and it worked well.


<add name="Telerik_Web_UI_WebResource_axd" path="Telerik.Web.UI.WebResource.axd"
                 type="Telerik.Web.UI.WebResource" verb="*"
                 preCondition="integratedMode,runtimeVersionv2.0"/>  




Thursday, October 13, 2016

0 and 1 String was not recognized as a valid Boolean - Boolean Parameter in SQLDatasource

String was not recognized as a valid Boolean, System.FormatException: String was not recognized as a valid Boolean,Boolean parameter SQLDataSource,Setting up Boolean Value SQLDataSource InsertParameters

I had a SQLDataSource with insert parameters and one of which data type was set to Boolean. And I was setting the default value for insert parameters in code behind.

aspx code:
<asp:Parameter Name="bIsActive" Type="Boolean" />


I assumed that 1 or 0 would naturally be converted into Boolean when I did this:

SqlDataSource1.InsertParameters["bIsActive"].DefaultValue = c.Checked ? "1" : "0";


But instead I saw this:

String was not recognized as a valid Boolean.
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.FormatException: String was not recognized as a valid Boolean.
Fig 1: String was not recognized as a valid Boolean


ASP.NET can easily convert 1 and 0 (integer types), but struggles with Strings.

Solution:


I used True and False strings instead of 0 and 1.

SqlDataSource1.InsertParameters["bIsActive"].DefaultValue = c.Checked ? "True" : "False";

Wednesday, October 5, 2016

Access denied error message while saving files on C drive - Windows 7

Access denied,Access denied saving files,Windows 7 Access Denied saving files, Windows 7 Cannot save files to Drive:,open text files as administrator

I have Windows 7 machine and have set myself as the Administrator. However, when trying to modify an XML file in Notepad and save the file, it states 'Access Denied!'. It will not save the file.



Below is the solution worked for me:

Step 1. Open the notepad application in elevated mode. This can be done by right click the Notepad icon from Windows > Click 'Run as administrator'.

Step 2. You can now edit and save that file in the same folder without any issues.



If you want to open the notepad elevated every time, then right click the Notepad shortcut icon > in 'shortcut' tab click on the 'Advanced' button > tick 'run as administrator'.



Win32Exception (0x80004005): The wait operation timed out

Win32Exception (0x80004005),Win32Exception (0x80004005) The wait operation timed out, The wait operation timed out,SQL Timeout expired
I was running an .NET console application that upon initial load pulls a list of items from a SQL server via a stored procedure. Within few seconds of loading the application, received the below error message:

Exception::System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out::Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.::.Net SqlClient Data Provider

Cause:
The problem was that the stored procedure took ~37 seconds to complete, which is slightly greater than the default timeout for a query to execute - 30 seconds. I figured this by executing the stored procedure manually in SQL Server Management Studio.

Resolution:
We need to set the CommandTimeout (in seconds) so that it is long enough for the command to complete its execution.

added the below line before filling the data adapter.
SqlCommand.CommandTimeout = 60; //60 seconds that is long enough for the stored procedure to complete.

Monday, October 3, 2016

Error Creating Control - Failed to create designer 'Telerik.Web.UI.

Telerik Error Creating Control,Error Creating Control Failed to create designer, Telerik Design time error,RadControls
You’ll find this error from time to time when switching to Design View in Visual Studio to work with Telerik Radcontrols, especially after Upgrading to a new version of Telerik UI for ASP.NET Ajax.


Causes:

  • There is a GAC-reference for the Telerik.Web.Design assembly in the project and the      GAC has been updated. As a result, the Telerik.Web.Design assembly, referenced by the WebSite, does not exist in the GAC.
  • The reference to the Telerik.Web.UI assembly (either in Register directive or web.config, or Telerik http handlers/modules registrations in web.config) contains hard-coded version number which does not match the version of the Telerik assembly referenced in your project.
  • Open the application in a machine that doesn't have Telerik UI Installed.


Fortunately there are several ways to solve this problem:

  • GAC Deploy the required version of the Telerik.Web.Design.dll.

The Telerik.Web.Design assembly contains the Visual Studio designers of the controls. 
          Telerik.Web.UI.dll requires Telerik.Web.Design.dll of the same version in the GAC.
Use the command gacutil /i [path to Telerik.Web.Design.dll with latest version]

  • Bin-deploy the design-time assembly Telerik.Web.Design.dll

Remove Telerik.Web.Design.dll from the GAC
Copy Telerik.Web.Design.dll to the bin folder
          Restart Visual Studio

  • Bin-deploy the assembly Telerik.Web.UI.Skins.dll
Copy Telerik.Web.Skins.dll to the bin folder
          Restart Visual Studio
  • In web.config file, removing the specific version, Culture, and PublicKeyToken from the Telerik.Web.UI.WebResource.axd entry.

         Correct Syntax:
        <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*"   validate="false"/>

The second solution did the trick for me. Hopefully one of the above solutions will work for you.

Thursday, October 8, 2015

How To Use a .NET 2.0 Runtime DLL From .NET 4.0 Windows Forms application?

I had a requirement to use a .NET dll assembly that was built against version 'v2.0.50727'to reference to it in my .Net Framework 4.0 windows forms application.

After referencing the dll, compilation error occurred in the application - "are you missing a using directive or an assembly reference."

Reason: As the DLL is a CLR 2.0 runtime assembly, it cannot be loaded in the 4.0 runtime.


Solution:

You will need to set useLegacyV2RuntimeActivationPolicy to true in app.config file. This is required to use mixed mode CLR 2 assemblies(targeting version 2.0.50727 of the CLR), in a .NET 4 application.

<startup useLegacyV2RuntimeActivationPolicy="true">
   <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>


Friday, June 21, 2013

No export DLLs found error – Crystal Reports


While attempting to export the crystal report on a terminal server, it resulted in the following run-time error:

"No export DLLs found".


This errors message appears because the application cannot find the export DLLs on terminal server environment.

Solution

I copied all the below export related dlls (U2*.dll) that are in C:\Windows\CRYSTAL Folder to C:\Windows\System32 Folder. The problem is very well solved.

Crystal Report Export Dlls

Dll NameDESCRIPTION
U2DAPP.DLLApplication destination
U2DDISK.DLLDisk file destination
U2DMAPI.DLLMAPI format (Microsoft Mail, Microsoft Exchange)
U2DNOTES.DLLLotus Domino destination
U2DPOST.DLLMicrosoft Exchange Public Folders
U2DVIM.DLLVIM destination
U2FCR.DLLCrystal Reports format
U2FDIF.DLLDIF format
U2FHTML.DLLHTML format See HTML under Additional Components for additional runtime information.
U2FODBC.DLLODBC data source
CRXF_PDF.DLLPDF format Replaces U2FPDF.DLL from version 8.See Page Ranged Export under Additional Components for additional runtime information.
U2FRDEF.DLLReport Definition format
U2FREC.DLLRecord format
CRXF_RTF.DLLRich Text FormatReplaces U2FRTF.DLL from version 8 and earlier.See Page Ranged Export under Additional Components for additional runtime information.
U2FSEPV.DLLComma Separated Values format
U2FTEXT.DLLText format
U2FWKS.DLLLotus 1-2-3 format
U2FWORDW.DLLMicrosoft Word for Windows format
U2FXML.DLLXML format
U2FXLS.DLLMicrosoft Excel format

Wednesday, June 9, 2010

Unable to find the requested .Net Framework Data Provider. It may not be installed.

SQL Errors and Solutions,.NET Errors and Solutions,Unable to find the requested .Net Framework Data Provider. It may not be installed.,.NET

I got this error "Unable to find the requested .Net Framework Data Provider. It may not be installed." when I try to retrieve the data from SQL Server.

Reason:


Whoo!!

I had wrongly mentioned the Data provider name in my dll.

I had mentioned as

Conndll.ProviderName = "System.Data.Sqlclient" 'c in client should have been upper case letter

instead of

Conndll.ProviderName = "System.Data.SqlClient"

Thursday, May 6, 2010

Not enough storage is available to process this command

Not enough storage is available to process this command
I recently faced an issue in the development server, the error message "Not enough storage is available to process this command" popped up when try to ran the longer query in the sql server.


Not enough storage is available
Not enough storage is available to process this command





The reason for the error was due to the  IPRStackSize registry entry was missing or setting too low.

In my case the IPRStackSize registry entry was missing .

To resolve these errors I did the following:

1) Start -> Run ->Type regedit
2) Locate and click the following entry
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters

3)If the IRPStackSize entry is not present in this subkey, follow these steps:


   Click Edit, point to New, and then click DWORD Value.

   Type IRPStackSize, and then press ENTER.

   Note: Type IRPStackSize exactly as it appears. The value name is case sensitive.

4) Right Click IRPStackSize and then click Modify.

IPRStackSize


5) Select the Base as decimal. In the Data Value box, type a larger value and then click OK.

Edit IPRStackSize

Wednesday, April 14, 2010

Value Close() cannot be called while doing CreateHandle()

The error Value Close() cannot be called while doing CreateHandle() usually happens when we try to close the form in the constructor or Load event.

For example,

the following code gives the error:


Private Sub RootForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load



'Some Validation
'If Failed then close the form
Me.Close 'The exception throws -->Value Close() cannot be called while doing CreateHandle()
End Sub

Solution:
The form should not be closed on load event. Instead we can write the procedure to close the form, and call the procedure in button click.

But the form cannot be closed during the loading point of time. So the form's closing call should be done after loading the form.

Wednesday, March 31, 2010

Items collection cannot be modified when the DataSource property is set

I received the following error "Items collection cannot be modified when the DataSource property is set"  when populating the combo box with data table.

Reason:

The Items.Clear method was called while the combo box's data source was assigned.

Solution:


Need to set the combo box's data source to nothing before calling Items.Clear method
 
The following sample code explains this scenario clearly.
 
Private Sub populateProducts()
Dim SQLAdapter As SqlDataAdapter = Nothing

Try

 
Dim strSQl As String = "SELECT ID, ProdName  FROM  tblProducts"
SQLAdapter = New SqlDataAdapter(strSQl, SConnectionString)

Dim dt As New DataTable

SQLAdapter.Fill(dt)

cmbProducts.DataSource = Nothing // Need to set the data source nothing
                                                           // Comment this line to reproduce the error

cmbProducts.Items.Clear()

cmbProducts.DataSource = dt


cmbProducts.DisplayMember = "ProdName"


cmbProducts.ValueMember = "ID"

Catch ex As Exception


lblStatus.Text = ex.Message
End Try
End Sub

Monday, March 29, 2010

The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine

I received the following error The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine'  in my 64-bit machine, Windows 2008 R2 when I ran by windows application.

But the same code was working fine in 32-bit machine.

Reason:

There is no 64-bit  Microsoft.Jet.OLEDB Provider.

Solution:

We need to forcibly build the application to 32-bit.




Steps

Goto Build ->Project Properties
Under the Compile Tab ->Click Advanced Compile Option..
Set  Target CPU to x86 instead of Any CPU

Wednesday, February 24, 2010

DBNull is a type and cannot be used as an expression

This is a compile time error which occurs when checking whether the value is System.DBNULL with the following statement..



If result Is System.DBNULL Then


End If



The correct statement should be



If result Is System.DBNULL.Value Then


End If

Wednesday, February 17, 2010

.NET Error: Class not registered Exception from HRESULT: 0×80040154

This error might occur when an ActiveX control is not registered in the machine. For example, the DSO Framer control (an ActiveX control to host office file) works fine in the local machine. After deployment in another machine, it might throw the error: “Class not registered

Reason:
An AciveX control needs to be registered before it can be used

How to register the active-x control?

1) Using regsvr32.exe (Manual registration)


The active-x control needs to be manually registred in that machine by using regsvr32.exe.
Go the the DOS prompt and type in "regsvr32.exe c:\DSOFramer.ocx".


2) During Deployment: (Best option)


1. Add the dsoframer.ocx in your Setup project
2. Set the Register property of this file to vsdrfCOM.
3. Build the Setup project and run the resulting MSI package to install your application as well as the DSOFramer ActiveX control on the target machine.

    Thursday, November 19, 2009

    .NET Error: Operator '<operatorname>' is not defined for types '<typename1>' and '<typename2>'

    Error Description:

    The error "Operator '<operatorname>' is not defined for types '<typename1>' and '<typename2>'" occurs When an attempt was made to use an operator in a way that is inappropriate for the specified types.

    Reason:

    This error can be caused by using the "=" operator instead of using the Is operator to compare two objects.


     

    Example:


     

    Private Sub toolBar_ButtonClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)


    If e.Button = toolBarButtonNew
    Then ' => Error Operator '=' is not defined for types 'System.Windows.Forms.ToolBarButton' and 'System.Windows.Forms.ToolBarButton'

          menuItemNew_Click(Nothing, Nothing)

    End If

     

    If e.Button <> toolBarButtonSave
    Then ' => Error Operator '<>' is not defined for types 'System.Windows.Forms.ToolBarButton' and 'System.Windows.Forms.ToolBarButton'

    menuItemNew_Click(Nothing, Nothing)

    End
    If

     

    End Sub

     

    Solutions:

    1. Use Is operator to compare two reference types.
    2. Use the Not operator in conjunction with the Is operator to denote inequality. 

    Replace


    1. "If e.Button = toolBarButtonNew
      Then"
      with "If e.Button Is toolBarButtonNew
      Then"

    2. "If e.Button <> toolBarButtonSave
      Then"
      with "If Not e.Button Is toolBarButtonSave
      Then"

    .NET Error: Implementing property must have matching 'Readonly' or 'Writeonly' specifiers

    Error Description:

    The compiler error Implementing property must have matching 'Readonly' or 'Writeonly' specifiers occurs When implementing property of the interface in the class.


    Example:
    Interface IComparer 

    Public Interface IComparer


    #Region "Methods"


    Private Function Compare(ByVal x As [Object], ByVal y As [Object]) As
    Integer

    ……

    #End Region

    End Interface


     

    Class Implements the property Compare of IComparer interface:

    Public Class DateTimeReverserClass

    Implements IComparer

    Private Function Compare(ByVal x As [Object], ByVal y As [Object]) As
    Integer //=> Error throws here

    Dim dx As DateTime = DirectCast(x, DateTime)
    Dim dy As DateTime = DirectCast(y, DateTime)
    If dx > dy Then
       Return -1
    Else
       Return 1
    EndIf

    End Function

    End Class

    Reason:
    The compiler is not able to find the matching property implementation on interface 'IComparer'
     

    Possible Solutions:

    The work around is to include the Implements clause to give the fully qualified name of the property (Format: Implements <Interface Name>.<Property Name>)

     

    In the above example, replace the line "Private Function Compare(ByVal x As [Object], ByVal y As [Object]) As Integer" with "Private Function Compare(ByVal x As [Object], ByVal y As [Object]) As Integer Implements IComparer.Compare"


     Public Class DateTimeReverserClass

    Implements IComparer


    Private Function Compare(ByVal x As [Object], ByVal y As [Object]) As
    Integer Implements IComparer.Compare

    Dim dx As DateTime = DirectCast(x, DateTime)

    Dim dy As DateTime = DirectCast(y, DateTime)

    If dx > dy Then
    Return -1
    Else
    Return 1

    EndIf

    End Function

    End Class


     

    Now the compiler error will not occur.

    SqlBulkCopy Error: The given value of type SqlDecimal from the data source cannot be converted to type decimal of the specified target column.

     

    Error Description:

    The given value of type SqlDecimal from the data source cannot be converted to type decimal of the specified target column.

    Reason:

    The error occurs during sqlbulkcopy when the destination table contains the Decimal column with same precision and scale. (E.g., The  table in SQLServer has column TestColumn  Decimal (3,3) )

    SELECT (cast(0.000 as decimal(3,3))) this will run fine in SQL, but will fail in bulk copy.

    Possible Solutions:

    Increase the precision size.

    I had the same problem when I worked on my data migration project.

    The work around was to increase the precision size by 1 if both the precision and scale are same for the Decimal Column type.

    Example:

    TestColumn Decimal (3,3) will fail in sql bulk copy.

    But

    TestColumn Decimal (3, 4) will work fine in sql bulk copy.

    Monday, August 31, 2009

    Cannot access destination table 'table-name' Error – During SqlBulkCopy

    Problem Description:

    The above error cannot access destination table might occur when bulk copying data to Sql server table using SqlBulkCopy.

    Possible Reasons:

    1. If the destination table name contains spaces

    2. If the destination table name contains - (hyphen) symbol

    Example:

    Using bulkCopy As SqlBulkCopy = _

    New SqlBulkCopy(targetConnectionString, SqlBulkCopyOptions.TableLock)

    bulkCopy.DestinationTableName = "abb po" '- This will Fail –Bcoz the table name contains space.

    bulkCopy.DestinationTableName = "abb-po" '- This will Fail –Bcoz the table name contains space.

    Try

    ' Write from the source to the destination.

    bulkCopy.WriteToServer(OdbcDr)

    Catch ex As Exception

    Console.WriteLine(ex.Message)

    End Try

    End Using

    Solution Description:

    The table name should be preceded and followed by "[" and "]" respectively.

    Example:

    Using bulkCopy As SqlBulkCopy = _

    New SqlBulkCopy(targetConnectionString, SqlBulkCopyOptions.TableLock)

    bulkCopy.DestinationTableName = "[abb po]" 'Correct Code

    bulkCopy.DestinationTableName = "[abb-po]" 'Correct Code

    Try

    ' Write from the source to the destination.

    bulkCopy.WriteToServer(OdbcDr)

    Catch ex As Exception

    Console.WriteLine(ex.Message)

    End Try

    End Using

    SQL BULK COPY error: invalid attempt to call fieldcount when reader is closed Error

    Problem Description:

    The error " invalid attempt to call fieldcount when reader is closed" can occur when bulk copying data to Sql server table using SqlBulkCopy.

    Consider the following example:

    The following example throws the error "Invalid attempt to call fieldcount when reader is closed"

    Example:

    ' Retrieval of the data from the source ODBC connection table

    Dim sODBCCmd As New OdbcCommand(strODBC, sODBCConn)

    sODBCConn.Open()

    OdbcDr = sODBCCmd.ExecuteReader()

    sODBCConn.Close() ' We are Closing the connection

    ' SQL Bulk Copy

    Using bulkCopy As SqlBulkCopy = _

    New SqlBulkCopy(targetConnectionString, SqlBulkCopyOptions.TableLock)

    bulkCopy.DestinationTableName = "[" & sTableName & "]"

    Try

    bulkCopy.WriteToServer(OdbcDr)

    Catch ex As Exception

    Console.WriteLine(ex.Message) ' Error Invalid attempt to call fieldcount when reader is closed

    End Try

    End Using

    Possible Reasons:

    The data reader is closed.

    sODBCConn.Close() (which closes the connection) after ExecuteReader() is called and thus closing the
    datareader (the datareader is tied to the connection).

    Remarks: The connection.Close() statement closes the data reader as well.

    Solution:

    We must either keep the connection open and close it and the reader when you are done with it, or make use of a dataset.

    sODBCConn.Open()

    OdbcDr = sODBCCmd.ExecuteReader()

    Using bulkCopy As SqlBulkCopy = _

    New SqlBulkCopy(targetConnectionString, SqlBulkCopyOptions.TableLock)

    bulkCopy.DestinationTableName = "[" & sTableName & "]"

    Try

    ' Write from the source to the destination.

    bulkCopy.WriteToServer(OdbcDr)

    Catch ex As Exception

    Console.WriteLine(ex.Message) ' Error Throws Here

    Finally

    OdbcDr.Close()

    sODBCConn.Close() ' Should be closed Here to avoid the error

    End Try

    End Using