[Oracle Client] Provider not found windows 7 x64 - Oracle Client


Description

    * Update 18 July 2017 ---------

     this is caused by the installation was not correct. for example case your application using ODAC (Oracle Data Access Component) like OLEDB or ODBC, but you install Oracle Client 10G 32bit. the oracle client install successful but the provider not list in unified data link (UDL).
    Or another case like this , when in win XP your application using MSDAORA (it's data component for oracle from microsoft) but in x64 Architecture MSDAORA not support so you must using ODAC for x64. microsoft not support anymore MSDAORA for x64.

Solution :

1. Disable UAC

    - 
Open User Account Control Settings by clicking the Start button , and then clicking Control Panel. In the search box, type uac, and then click Change User Account Control settings.

    - move the slider to the Never notify position, and then click OK If you're prompted for an administrator password or confirmation, type the password or provide confirmation. 
   
    - Don't forget to RESTART THE COMPUTER (it doesn't effect if you not restart).


2. you must install the correct architecture oracle client, if the target machine use x86 architecture use oracle client x86. but if the target machine use x64 architecture use x64 instead. Advised to renew the oracle client form 10G to 11G..

here's the link, before download register account first and accept the agreement on the top of page
x86 or 32bit
Oracle Database 11g Release 2 Client (11.2.0.1.0) for Microsoft Windows (32-bit)

x64 or 64bit
Oracle Database 11g Release 2 Client (11.2.0.1.0) for Microsoft Windows (x64).

*path installation example "
d:\oracle\product\11.2.0\client_1\


3. Download Oracle Data Access 64-bit (ODAC x64) DOWNLOAD HERE and extract it (in my case i extract to d:\oracle\odac *you can put anywhere).


4. Open CMD in Administrator Mode and navigate to d:\oracle\odac.

5. Execute command line from CMD :
    install.bat all D:\oracle\product\11.2.0\client_1\ odac
    * wait until finish install

6. After finish navigate D:\oracle\product\11.2.0\client_1\ODP.NET\bin\4\
   execute command :
   OraProvCfg.exe /action:gac /providerpath:D:\oracle\product\11.2.0\client_1\ODP.NET\bin\4\Oracle.DataAccess.dll

7. Next, navigate : D:\oracle\product\11.2.0\client_1\ASP.NET\bin\4\
    execute command :
      OraProvCfg.exe /action:gac /providerpath:D:\oracle\product\11.2.0\client_1\ASP.NET\bin\4\Oracle.web.dll

8. Now setting environment variable path, on system variable :
    Add New :
    ORACLE_HOME : D:\oracle\product\11.2.0\client_1\
    TNS_ADMIN : D:\oracle\product\11.2.0\client_1\network\admin

    Add PATH:  
    xxxxx;%ORACLE_HOME%;%TNS_ADMIN%

9. Change connection provider from "msdora.1" to "oraoledb.oracle"

10. andddddd it's MAGICCC !!!
   

[VB.NET] Read and Write Inifile (.ini)


Description
     IniFile is a file used to store data that will be used by an application or another application interface. very useful for storing small amount of data such as startup settings and others. IniFile uses almost same as XML. just the use of XML wider than IniFile. 

IniFile also have one advantage that it's light as a text file (. Txt). very suitable for storing small amounts of data settings for lightweight applications. if somewhat complex applications use XML.

Howto
    1. Api Declaration, create a module and write this Windows API :
'wind32 API IniFile
    Private Declare Auto Function GetPrivateProfileString Lib "kernel32" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
    Public Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

  2. Create function to write IniFile:
    'function Write IniFile
    Public Function WriteIni(ByVal sSection As String, ByVal sKeyName As String, ByVal sNewString As String, ByVal sFileName As String) As Integer
        Dim Vb
        Vb = WritePrivateProfileString(sSection, sKeyName, sNewString, sFileName)
    End Function

  3. Create function to read IniFile:
    Public Function ReadIni(ByVal Key As String, ByVal SubKey As String, ByVal strFileName As String) As String
    Dim res As Integer
    Dim data As StringBuilder

    data = New StringBuilder(500)
    res = GetPrivateProfileString(Key, SubKey, "", data, data.Capacity, strFileName)
    Return data.ToString
    End Function

  4. How to call ?
      - to write just call : WriteIni("app_header", "variable", value, "d:\pathinifile.ini")
        the result in Inifile :
        [app_header]
        variable=value
   
       - to read just call : myvar = ReadIni("app_header", "variable", "d:\pathinifile.ini")
         the result : myval = value

   5. a little additional information , if you need to check file existing for example inifile exist or not , you can use this, create function FileExist
    'function check file exist
    Public Function FileExists(ByVal sFileName As String) As Boolean
        Dim intReturn As Integer
        Try
            intReturn = GetAttr(sFileName)
            FileExists = True
        Catch
            Exit Function
            FileExists = False
        End Try
    End Function
   - to use : FileExists("d:\pathinifile.ini"), it will return true if file exist and false if file not found.

works great

[VB.NET] Kill Process Excel


Description
      If you use vb.net to generate excel but the process excel cannot be terminate, this would be a serous problem , because if you do the work repeatedly excel process will accumulate and this will make the memory becomes full the effect of windows can be hang and it's dangerous. to prevent this we must kill the excel process but if you open another excel it will closed too. the solution is simply that you must find the process id of the object, and kill that object by id.

How to
1. i will give sample code below (create object excel)

        Dim oexcel As Object
        Dim obook As Object
        Dim osheet As Object

       'create Object excel
        Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
        oexcel = CreateObject("Excel.Application")
        obook = oexcel.workbooks.Add
        osheet = obook.worksheets(1)

       'Create Header First  
       osheet.Range("A1").Value = "Header 1"
       osheet.Range("B1").Value = "Header 2"
            
       osheet.Range("A2").Value = "Cell 1"
       osheet.Range("B2").Value = "Cell 2"

       oexcel.DisplayAlerts = False
       obook.SaveAs("D:\myfile.xls")
       oexcel.Quit()
       oexcel = Nothing
       MsgBox("Extract to Excel Complete, file save in :" & "D:\myfile.xls")

* the code above only create object excel and write some value into file, but it not close the process yet. to create kill excel process by PiD we must create sub and call it.

2. Create sub "killCurrentExcel()" 
    - first step we must declare win32 API. create a module and write this :
          'win32 API
    Public Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hWnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer
    Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

   - After win32 API has been declare , create the function : 
      Public Sub killCurrentExcel (ByVal oexcel As Object)
        Dim proc As System.Diagnostics.Process
        Dim intPID As Integer
        Dim intResult As Integer
        Dim iHandle As IntPtr
        Dim strVer As String

        strVer = oexcel.Version
        iHandle = IntPtr.Zero
        If CInt(strVer) > 9 Then
            iHandle = New IntPtr(CType(oexcel.Parent.Hwnd, Integer))
        Else
            iHandle = FindWindow(Nothing, oexcel.Caption)
        End If
        oexcel.Workbooks.Close()
        oexcel.Quit()
        Marshal.ReleaseComObject(oexcel)
        oexcel = Nothing
        intResult = GetWindowThreadProcessId(iHandle, intPID)
        proc = System.Diagnostics.Process.GetProcessById(intPID)
        proc.Kill()
      End Sub
      
3. Call killCurrentExcel() before messagebox of the excel with format : 
      killCurrentExcel("your object excel here")  so it will be "killCurrentExcel(oexcel)"

4. Here's the full listing :
    ' sub for generate excel
    Public Sub generateExcel()
        Dim oexcel As Object
        Dim obook As Object
        Dim osheet As Object

       'create Object excel
        oexcel = CreateObject("Excel.Application")
        obook = oexcel.workbooks.Add
        osheet = obook.worksheets(1)
        Try
            'Create Header First  
            osheet.Range("A1").Value = "Header 1"
            osheet.Range("B1").Value = "Header 2"
            
            osheet.Range("A2").Value = "Cell 1"
            osheet.Range("B2").Value = "Cell 2"

            oexcel.DisplayAlerts = False
            obook.SaveAs("D:\myfile.xls")
            oexcel.Quit()
            killCurrentExcel(oexcel)
            oexcel = Nothing
            MsgBox("Extract to Excel Complete, file save in :" & "D:\myfile.xls")
    end sub

    'sub for kill process by PiD
    Public Sub killCurrentExcel (ByVal oexcel As Object)
        Dim proc As System.Diagnostics.Process
        Dim intPID As Integer
        Dim intResult As Integer
        Dim iHandle As IntPtr
        Dim strVer As String

        strVer = oexcel.Version
        iHandle = IntPtr.Zero
        If CInt(strVer) > 9 Then
            iHandle = New IntPtr(CType(oexcel.Parent.Hwnd, Integer))
        Else
            iHandle = FindWindow(Nothing, oexcel.Caption)
        End If
        oexcel.Workbooks.Close()
        oexcel.Quit()
        Marshal.ReleaseComObject(oexcel)
        oexcel = Nothing
        intResult = GetWindowThreadProcessId(iHandle, intPID)
        proc = System.Diagnostics.Process.GetProcessById(intPID)
        proc.Kill()
      End Sub

   in module declare 2 Win32 API :
       Public Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hWnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer
    Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    

works great :D
   

[VB.NET] DataGridView using ADODB


Description
      Display data from database to DataGridView using ADODB.

HowTo

1. Add Refferences
       Project>Refferences>Microsoft Active X Data Object 2.7 Library
       or you can add manual in path :
       C:\Program Files\Common Files\system\ado\msado.tlb


2. Import ADODB on your project
     Imports ADODB.CursorOptionEnum
     Imports ADODB.CursorLocationEnum
     Imports ADODB.CommandTypeEnum
     Imports ADODB.CursorTypeEnum
     Imports ADODB.DataTypeEnum
     Imports ADODB.RecordStatusEnum
     Imports ADODB.RecordTypeEnum
     Imports ADODB.LockTypeEnum
     Imports ADODB.ObjectStateEnum

3Here's the sample syntax :
        Dim adaptor
        Dim ds As DataSet = New DataSet()
        Dim strsql As String
        Dim RSSQLSERVER As ADODB.Recordset

        ConnectSQLServer = New ADODB.Connection
        ConnectSQLServer.Open("FILE NAME=" & My.Application.Info.DirectoryPath & "\SQLServer.udl")

        ' Create Object Recordset
        RSSQLSERVER = New ADODB.Recordset
        RSSQLSERVER.CursorLocation = adUseClient

        strsql = "select * From mytable"
        ' Check Status Record set , already Open or Still Close
        If RSSQLSERVER.State <> adStateClosed Then RSSQLSERVER.Close()
        'FILL Recordset with data from Database
        RSSQLSERVER.Open(strsql, ConnectSQLServer, adOpenKeyset, adLockOptimistic)
        RSSQLSERVER.ActiveConnection = Nothing
        ConnectSQLServer.Close()

        'Check Record Count
        If RSSQLSERVER.RecordCount > 0 Then
           'if record found to do here
        Else
           'if no record to do here
        End If

        'this code below will populate the datagrid but will closed current active connection , so display the data first before using this code.
        adaptor = New OleDbDataAdapter()
        adaptor.Fill(ds, RSSQLSERVER, "mytable")
        dataGridView1.Datasource = ds.Tables(0).DefaultView

works great ;)