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

Wednesday, July 1, 2009

Create Store Procedure In Oracle For Count and Call from Vb.NET Code

-----------------------------
Create procedure in Oracle:
-----------------------------
create or replace PROCEDURE SP_GET_UserCOUNT (returnval out number) AS
BEGIN
select count(*) into returnval from (select * from usertable);

END SP_GET_UserCOUNT;

-----------------------------
Call form you vb function
-----------------------------
#Region "getUserCount"
Public Shared Function getUserCount() As Integer
Dim returncount As Integer
Try

'Using conn As OracleConnection = New OracleConnection(connecitonstring)
Using conn As OracleConnection = New OracleConnection(My.Settings.sConnectionString)
conn.Open()

Dim cmdTyProcessTbl As OracleCommand = New OracleCommand("", conn)
cmdTyProcessTbl.CommandText = "SP_GET_UserCOUNT"
cmdTyProcessTbl.CommandType = Data.CommandType.StoredProcedure

Dim prm As OracleParameter = New OracleParameter("a", OracleDbType.Int32)
prm.Direction = Data.ParameterDirection.Output
cmdTyProcessTbl.Parameters.Add(prm)

cmdTyProcessTbl.ExecuteNonQuery()
cmdTyProcessTbl.Dispose()

returncount = prm.Value.ToString

conn.Close()
conn.Dispose()
GC.Collect()
End Using

Return Convert.ToInt32(returncount)

Catch ex As Exception
Throw ex
End Try
End Function
#End Region

Tuesday, June 23, 2009

Learn how to scale your application cache on multiple servers (really cool)

Developer now can scale there .NET application objects in cache from string to binary objects using "Velocity"

Overview: Microsoft project code named “Velocity” provides a highly scalable in-memory application cache for all kinds of data. By using cache, you can significantly improve application performance by avoiding unnecessary calls to the data source. Distributed cache enables your application to match increasing demand with increasing throughput by using a cache cluster that automatically manages the complexities of load balancing. When you use “Velocity,” you can retrieve data by using keys or other identifiers, named “tags.” “Velocity” supports optimistic and pessimistic concurrency models, high availability, and a variety of cache configurations. “Velocity” includes an ASP.NET session provider object that enables you to store ASP.NET session objects in the distributed cache without having to write to databases, which increases the performance and scalability of ASP.NET applications.
You can checkout this webcast for complete understanding:
http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032413050&EventCategory=5&culture=en-US&CountryCode=US

Saturday, June 6, 2009

Retrieve Images that are saved in your Oracle tables as Blog

Ok. If you have images that are saved in your blob field. You can download then into your code as shown below.

Please don't forget visit my website at: www.lendmyspace.com and www.lookfordeal.com

Public Function saveBlobImages() As Single
Dim sqlStr1 As String
Dim cmd As New OracleClient.OracleCommand
Dim oraDa As OracleDataAdapter
Dim conn As OracleConnection = Nothing
Dim ms As MemoryStream = Nothing
Dim dsImage As Data.DataSet = Nothing
Dim myBytes() As Byte = Nothing
Dim imgJPG As System.Drawing.Image = Nothing
Dim msOut As MemoryStream = Nothing

Try

sqlStr1 = "select Image_Name, image_ID, blob_image from image_table where rownum < 100"

' Initialize connection
oraDa = New OracleDataAdapter(sqlStr1, My.Settings.sConnectionString)
conn = oraDa.SelectCommand.Connection
dsImage = New Data.DataSet()
oraDa.Fill(dsImage, "ImageTifImages")

If dsImage.Tables(0).Rows.Count = 0 Then
Throw New Exception("No results returned for rows")
Else

For i As Integer = 0 To dsImage.Tables(0).Rows.Count - 1

myBytes = dsImage.Tables(0).Rows(i)("blob_image")
ms = New MemoryStream
ms.Write(myBytes, 0, myBytes.Length)
imgJPG = Image.FromStream(ms)

'Export to TIF Stream
msOut = New MemoryStream
imgJPG.Save(msOut, System.Drawing.Imaging.ImageFormat.Jpeg)
imgJPG.Dispose()
imgJPG = Nothing
ms.Write(myBytes, 0, myBytes.Length)
imgJPG = System.Drawing.Image.FromStream(ms)
Dim filename As String = dsImage.Tables(0).Rows(i)("Image_Name").ToString + "_" + dsImage.Tables(0).Rows(i)("Image_id").ToString
filename = filename.Replace(".txt", "")
imgJPG.Save(filename + ".Tif")
ms.Close()
Next
End If

Catch ex As Exception
Throw
End Try

End Function

Thursday, May 21, 2009

Azure - Simple Applicaiton - Security Exception Error

I have recently deploy Azure Application to see how Microsoft Cloud Application will work. In this process I come across Security Exception Error which took me while to figure out. So, if you have same issue make sure you do the following:

Here is the error message:

Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.

1. In your "could" project make sure you open ".csdef" file and edit the following
WebRole name="WebRole" enableNativeCodeExecution="true">

Make sure you have enableNativeCodeExecution="true"

2. You should also make your "web_role" project open web.config file and make sure you have the following:


3. If you page still gives error message then you set all your <@Page Debug = "true"

4. Make sure you have customErrors mode="Off" in web.config file


This should make your application work on Azure Cloud Please don't forget to visit my website at: http://www.lookfordeal.com

Tuesday, May 12, 2009

Oracle Package - Basics

Here is a sample of oracle package in which I will send startIndex as integer and endIndex as integer. In returns it will return me customer list

create or replace PACKAGE BODY PKG_GET_THANKYOU_customer_LIST AS

procedure getThankyouNames(startIndex IN number, endIndex in number,myMethodCode in varchar2, out_cursor OUT Thank_Cur) AS

localThank_Cursor Thank_cur;
BEGIN
/* TODO implementation required */
/* delete from temp_ty; */
insert into temp_thankyou_cust_list
select t3.customer_sid, ws1.order_sid, t2.order_code,max(ws1.order_date) order_date, rnum,t3.cust_company_name,
t3.cust_name,t3.cust_title, t3.cust_Phone, t3.cust_phone_ext, t3.cust_fax, t3.cust_STREET_ADDR_LINE1,
t3.cust_STREET_ADDR_LINE2,t3.cust_CITY,t3.cust_ZIP_CODE,t3.cust_ZIP_PLUS4,t3.cust_STATE_CODE,
t3.MY_METHOD_CODE
from work_table_order t2, work_spec_table ws1,
(select * from
(select t1.*, rownum rnum from
(select distinct c1.customer_sid, c1.cust_company_name, c1.cust_name,
c1.cust_title, c1.cust_Phone, c1.cust_phone_ext, c1.cust_fax,
c1.cust_STREET_ADDR_LINE1, c1.cust_STREET_ADDR_LINE2, c1.cust_CITY,
c1.cust_ZIP_CODE,c1.cust_ZIP_PLUS4,c1.cust_STATE_CODE,c1.RPC_METHOD_CODE
from customer c1, work_productive_order wp1
where c1.MY_METHOD_CODE = myMethodCode and c1.customer_sid = wp1.customer_sid
and wp1.customer_sid not in (select customer_sid from thankyou_customers)
order by c1.customer_sid
) t1
where rownum <= endIndex
)
where rnum >= startIndex
) t3
where t2.customer_sid = t3.customer_sid and ws1.order_sid = t2.order_sid
group by ws1.order_sid,t2.order_code, t3.customer_sid, rnum, t3.cust_company_name, t3.cust_name,
t3.cust_title, t3.cust_Phone, t3.cust_phone_ext, t3.cust_fax, t3.cust_STREET_ADDR_LINE1,
t3.cust_STREET_ADDR_LINE2,t3.cust_CITY,t3.cust_ZIP_CODE,t3.cust_ZIP_PLUS4,t3.cust_STATE_CODE,t3.MY_METHOD_CODE;
open localThank_Cursor for
select ty1.*, substr(ws1.text_description,1,50)
from temp_thankyou_cust_list ty1, work_spec_table ws1
where ty1.order_sid = ws1.order_sid and ty1.order_date = ws1.order_date
order by ty1.customer_sid, ty1.order_code;
out_cursor := localThank_Cursor;

END getThankyouNames;

END PKG_GET_THANKYOU_cust_LIST;

Wednesday, April 8, 2009

How to bring data from One Schema to Second Schema in Oracle

This is specify to Oracle 11

If you need to bring (transfer) data from older database schema (UDBTEST) to new schema (UDBBETA) in oracle database then you will follow there procedures:

1- Create a Link between both schema(s)
2- Run insert query

Step: 1 For this step you must have admin permission on database

ORACLE LINKS
HERE SOURCE IS UDBTEST and target is UDBBETA. Link is created in target and accessed in target.

Run it from UDBBETA:
select count(*) from team1_user@UDBTEST2BETA;

Link created in udbbeta connected to udbtest.:
CREATE PUBLIC DATABASE LINK UDBTEST2BETA
CONNECT TO 'yourusername' IDENTIFIED BY 'yourpassword'
USING 'udbtest'
/

Step 2: Run this command
Insert into
Select * from @UDBTEST2UDBBETA;

commit;

Thursday, March 19, 2009

How to delete files and folder from network drive

Hi, In this sample I will show you how to delete files and folder from your hard drive using VB.NET code.

Let me first explain in words how this will work

DELETE FILES

1. I will get all see if direcoty exists
2. I will delete all files inside "AdnanKhan" directory

Dim sPathTok As String
sPathTok = My.Settings.FilePathName
If IO.Directory.Exists(sPathTok) Then
Dim dir As DirectoryInfo = New DirectoryInfo(sPathTok)
Dim files As FileInfo() = dir.GetFiles
For Each f As FileInfo In files
If f.Name.StartsWith("AdnanKhan") Then
f.Delete()
End If
Next

myLog.WriteLog("Processed: Deleted")

Else
myLog.WriteLog("Processed: Directory Does Not Exists")
End If


'Delete all Directories
Dim sPathDir As String
sPathDir = My.Settings.FilePathNameDir
If IO.Directory.Exists(sPathDir) Then
Dim dir As DirectoryInfo = New DirectoryInfo(sPathDir)
Dim dirs As DirectoryInfo() = dir.GetDirectories
For Each d As DirectoryInfo In dirs
If d.Name.StartsWith("AK") Then
d.Delete(True)
End If
Next
myLog.WriteLog("Process #1: Directories Deleted")
Else
myLog.WriteLog("Process #1: Directory Does Not Exists")
End If

Thank You

Tuesday, March 17, 2009

Wednesday, March 4, 2009

How to make Connection to Oracle from VB.NET

How to connect to Oracle Database using VB.NET

1. You can make a variable into your My Project > Settings
call this variable : sConnectionString
and in value connection string as shown below.

Source=(DESCRIPTION=(ADDRESS_
LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=servername.mycompany.com)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=dev.mycompany.com)));

Note: please make sure you put your servers information in : Host and Service_Name

Now go to the windows form or asp.net page:

Imports this into your page:

Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types

Note: if you can't find this in you project then you download this from oracel website :
Oracle Dll: Oracle.DataAccess.dll
version: 2.102.2.20

Declare Private Variable in your Form1.VB Page:

Private Shared sConnectionString As String = My.Settings.OracleConnectionString

Here is the function:
Public Function ProcessErrorFixDataCheck(ByVal itemNum As String) As Boolean
Dim sqlStr As String
Dim cmd As New Oracle.DataAccess.Client.
OracleCommand
Dim oraDa As OracleDataAdapter
Dim conn As OracleConnection = Nothing
Dim ds As Data.DataSet
Try

sqlStr = "select item_Num from itemTable where item_Num = '" & itemNum & "'"

' Initialize connection
oraDa = New OracleDataAdapter(sqlStr, sConnectionString)
conn = oraDa.SelectCommand.Connection
ds = New Data.DataSet()
oraDa.Fill(ds, "ItemCount")


If ds.Tables(0).Rows(0)(0) IsNot Nothing Then
Return True
Else
Return False
End If

Catch ex As Exception
Throw ex
Finally
cmd.Dispose()
conn.Close()
conn.Dispose()
GC.Collect()
End Try
End Function

Wednesday, February 18, 2009

VB.NET - How to print graphics from windows form

Here how you will print image from your windows application

step 1:
Imports System.Drawing.Printing
Imports System.Drawing.Imaging

step2:
Drag and drop PrintDocument Control on your windows form and rename control name to: PrintGraphicControl

step3:
Put this in your code

Dim GraphicLocation as TextBox = New TextBox()
GraphicLocation.Text = "c:\myimage.jpg"
AddHandler PrintGraphicControl.PrintPage, AddressOf Me.GraphicPrint
PrintGraphicControl.Print()

#Region "Print Graphics"
Private Sub GraphicPrint(ByVal sender As Object, ByVal e As PrintPageEventArgs)
e.Graphics.DrawImage(Image.FromFile(GraphicLocation.Text), e.Graphics.VisibleClipBounds)
e.HasMorePages = False
End Sub
#End Region

Tuesday, February 17, 2009

LendMySpace.Com is just launched




LendMySpace.Com is just launched.

About LendMySpace

LendMySpace.Com is online media ad service to all of ours users who would like to sell their new/old item(s) or services online through our website. We make every effort to make buying and selling more interactive by providing a forum where the buyer and seller can easily contact each other. We strive to do this through advanced technology, in-depth research and above all the highest quality of customer service delivered with a sense of warmth, understanding, respect, and company spirit.

So please take sometime to visit us at: http://www.lendmyspace.com