Wednesday, October 14, 2009

How to use Oracle CHANGE NOTIFICATION Callback in .net application

How to use CHANGE NOTIFICATION Callback in .net application

1. You must give Grant permission on to your tables as shown below

grant change notification to database name

2. You have to registered your select query into database using your .net application as show below

below is code to register query

Public Sub ChangeNotification()
Try
Dim sql As String = "select firstname, lastname from person”

Dim constr As String = My.Settings.sConnectionString
Dim con As New OracleConnection(constr)

con.Open()

Dim cmd As New OracleCommand(sql, con)
Dim dep As New OracleDependency(cmd)
AddHandler dep.OnChange, AddressOf OnDatabaseNotification

cmd.ExecuteNonQuery()

While notificationReceived = False

Console.WriteLine("Waiting for notification...")
System.Threading.Thread.Sleep(2000)
End While

cmd.Dispose()
con.Dispose()

Console.WriteLine("Press ENTER to continue...")
Console.ReadLine()

Catch ex As Exception
Throw ex
End Try
End Sub

below is code to when data is updated or changed oracle database calls this event in your application

Public Sub OnDatabaseNotification(ByVal src As Object, ByVal args As OracleNotificationEventArgs)
Try
Console.WriteLine("Database Change Notification received!")
Dim changeDetails As DataTable = args.Details
Console.WriteLine("Resource {0} has changed.", changeDetails.Rows(0)("ResourceName"))

notificationReceived = True

Catch ex As Exception

Throw ex
End Try
End Sub

3. run this application and change/update your table information see this event called from oracle database

Enjoy !

Friday, October 2, 2009

Simple Update in Oracle Table Using Transaction from ASP.NET

 

First Create Simple Update Procedure in your oracle databae

------------------------------------------------------------------

create or replace

PROCEDURE SP_UPD_MYPROC(myid Nvarchar2, mytime TimeStamp) AS BEGIN

/* UPDATE */

Update mytable s set my_datetimefield =mytime where s.id = id; commit; END SP_UPD_MYPROC;

This is how you will call from your asp.net application using transaction

-------------------------------------------------------------------------------------------------------

Make sure you imports these libraries

Imports Oracle.DataAccess.Client

Imports Oracle.DataAccess.Types

Public Function UpdateMyTable(ByVal myId as string)

Dim txn As OracleTransaction = Nothing

Try

Using conn As OracleConnection = New

OracleConnection(My.Settings.sConnectionString)

conn.Open()

txn = conn.BeginTransaction()

Dim cmdTyProcessTbl As OracleCommand = New OracleCommand("", conn)

cmdTyProcessTbl.CommandText = "SP_UPD_MYPROC"

cmdTyProcessTbl.CommandType = Data.CommandType.StoredProcedure

Dim prm As OracleParameter = New OracleParameter("a", OracleDbType.NVarchar2)

prm.Direction = Data.ParameterDirection.Input

prm.Value = myId

cmdTyProcessTbl.Parameters.Add(prm)

prm = New OracleParameter("b", OracleDbType.TimeStamp)

prm.Direction = Data.ParameterDirection.Input

prm.Value = Now()

cmdTyProcessTbl.Parameters.Add(prm)

cmdTyProcessTbl.ExecuteNonQuery()

cmdTyProcessTbl.Dispose()

txn.Commit()

conn.Close()

conn.Dispose()

'file.Dispose()

txn.Dispose()

GC.Collect()

End Using

Catch ex As Exception

Throw ex.Message.ToString

Finally

GC.Collect()

End Try

End Function

That’s All !

How to register any third party control in windows application if registration key comes from third party website via URL using ASP.NET

In General you can use WebBrowser windows control to get registration key from the third party web site and use it into your windows application like this

Call first your url which will machineid as your key like this:
WebBrowser1.Navigate("https://www.my.com/machineid.html")

Then in WebBrowser1_Navigated event handler:

Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated

Dim mywebclient As New WebBrowser

Dim str As String = WebBrowser1.DocumentText
Dim machineid As String
If counter = 2 Then
      machineid = Mid(WebBrowser1.Url.Query, InStr(WebBrowser1.Url.Query, "arch=") + 5, InStr(WebBrowser1.Url.Query, "&days") - (InStr(WebBrowser1.Url.Query, "arch=") + 5))

      WebBrowser1.Navigate("https://www.cartesianinc.com/Prepaid/Ops/GetLicense.cgi?accountID=username&accountPW=yourpassword&machineID=" & machineid.ToString)

End If
If counter = 3 Then
Dim regkey As String = WebBrowser1.Document.Body.InnerText
         regkey = regkey.Split(">")(1).Split("<")(0)

      WebBrowser1.DocumentText = "<html>" & "<header>" & "/<header>" & "<body>" & "<embed type=""image/cpi"" width= ""100"" height=""100""" & " regkey=""" & regkey & """>" & "</body>" & "</html>"

End Sub

That’s all!

Thursday, October 1, 2009

How to automatically register CpcView Registration Key Using ASp.NET Web Forms

I came cross problem where i have to register activex control via web application. I thought putting this sample will help other users who can use my code for further registration key which are on provided on third party website. such as cartesiannic where we have to send user and password information and they post regkey on there website. So this is how I have used to register this automatically via web application

If you ever used cartesianinc cpc view controls then you can register components via website automatically

Page 1. will have in html source code: (uncomment code below)
<!--embed type="image/cpi" width="0" height="0" redirect='<%=href%>'-->

Page 1. Code behind will have:

Imports System.Web
Partial Public Class _Default
Inherits System.Web.UI.Page
Dim embed_src As String = "RegisterCPCView.aspx"

Property href() As String
Get
Return embed_src
End Get
Set(ByVal value As String)
embed_src = value
End Set
End Property 'href

End Class

In your Page 2 "RegisterCPCView" form you will write:

Imports System
Imports System.Xml
Imports System.IO
Imports System.Net

Partial Public Class RegisterCPCView
Inherits System.Web.UI.Page

Private accountID As String = "username"
Private accountPW As String = "password"
Private regKey As String = ""
Private myPageInstace As New Control
Private fs As FileStream
Private URL As String = ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'reg.cgi?product=cpcview&build=33&autoreg=0&license=individual&version=6.5.1AX&arch=33333&days=333&docs=33

Dim arch As String = ""
arch = Request.QueryString("arch")
Dim cartesianURL As String = "http://www.cartesianinc.com/Prepaid/Ops/GetLicense.cgi"
URL = cartesianURL + "?accountID=" + accountID + "&" + "accountPW=" + accountPW + "&" + "machineID=" + arch

GetKey()
End If
End Sub

Property href() As String
Get
Return regKey
End Get
Set(ByVal value As String)
regKey = value
End Set
End Property 'href

Private Sub GetKey()
Dim objWebClient As New WebClient()
Dim strURL As String = URL
Dim objUTF8 As New UTF8Encoding()
Dim htrmlSource As String = objUTF8.GetString(objWebClient.DownloadData(strURL))

href = Mid(htrmlSource, 9, 16)

Response.Redirect("~/RegisterCPCViewComplete.aspx?reg=" + href)
End Sub

End Class

In your Page 3 "RegisterCPCViewComplete.aspx" you will register the reterive registration key which you have get back from : "http://www.cartesianinc.com/Prepaid/Ops/GetLicense.cgi" third party

Page 3 Html Source Code:(uncomment code below)
<!--embed type="image/cpi" width="0" height="0" regKey='<%=href%>'-->

Page 3 Code behind:
Public Partial Class RegisterCPCViewComplete
Inherits System.Web.UI.Page
Private regKey As String = ""

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not String.IsNullOrEmpty(Request.QueryString("reg")) Then
href = Request.QueryString("reg")
End If
End Sub

Property href() As String
Get
Return regKey
End Get
Set(ByVal value As String)
regKey = value
End Set
End Property 'href
End Class

Thank You.
Please don't forget to visit:

http://www.netfixllc.com
http://www.lendmyspace.com
http://www.lookfordeal.com