Friday, September 12, 2008

CIs: Connecting to PeopleSoft Jolt sever from VB.net. Why & How. Part 1

[If you are looking to Load 100k+ rows into PeopleSoft quickly, this isn't the post for you! This is a multi post piece on Component Interfaces. Hopefully it is informative reading...]

Part 1:

There have been a lot of times when we have needed to mass load some sort of data. One of the main issues as always been load directly into PeopleSoft DB tables is just yucky... :) Some times unavoidable, but almost always yucky... I guess i should explain what i mean by yucky... The clearest example is person bio demo data. When you use 'add/update a person' to add a new person the emplid is give to you, the person's data is strewn over a plethora of tables and all the effective dating stuff is taken care of for you. Not to even touch on search match possibilities; cause we all love dupes so much...

Moving data around between platforms is always a headache. Then there is the migraine called synchronizing data... anyway, say you have an application that really needs data moved from it to Oracle's PeopleSoft. You could write something to connect to both DB and just pass data back and forth, but you want a solution that is more flexible, able to be used by an end user (securing DB level access for end users, do i need to say more...) and you want to be able to leverage data validation from the application tier. Sounds great. You have two options: CI or Web service.

As of 8.48, web services are a good option, but they are still lacking some (this could totally be from a lack of understanding from my part) and are a little ... um.. clunky?... when it comes to dealing with re-posts and data validation. They are great for posting small data objects from remote systems that you can almost be curtain the data is always good.

I have come to really have an appreciation for CIs. At first I really didn't like them because of the fact that they are based on old COM objects, don't work too nicely with .Net (I now have some tricks... :), setting up the environment was a pain, maintaining distributions was painful too and they are inherently SLOW (slow-as-a-wet-week). After I overcame these little hurdles, or learnt to live with them, the results are quite workable.

Windows Folder Share / Mapping Issue

Just hit a problem... "The network folder is currently mapped with a different username/password" even though from "My Computer" I can't see anything mapped...

Found an amazingly helpful blog at:
http://travisepperson.blogspot.com/2007/01/windows-network-folder-specified-is.html

Short version:
dropped to command line i.e. "start Run cmd"
Ran: net use

found the the offending share.

net use ">" /delete

Re-map network drive. Worked like a charm!


Thanks Mr. Epperson!!!!

Create a MD5 Hash in VB.Net

Creating a compliant MD5 Hash was a tough find for VB... I looked all over the place and found people doing all kinds of thing for hashes... But I needed one that would be the same as a Perl/PHP hash... After a lot of searching, I mashed together (as most of us do) a couple of ideas about the cryproservices and string building to come up with this...


Imports System.Security.Cryptography

Public Function Md5Hasher(ByVal StringToHash As String) As String
Dim md5Crypter As MD5
md5Crypter = MD5CryptoServiceProvider.Create
Dim DataBytes() As Byte = md5Crypter.ComputeHash(Encoding.Default.GetBytes(StringToHash ))
Dim strbldr As StringBuilder = New StringBuilder
Dim i As Integer
For i = 0 To DataBytes.Length - 1
strbldr.AppendFormat("{0:x2}", dataMd5(i))
Next

Return strbldr .ToString

End Function

Oracle Data Reader to Data Table VB.Net

One of the things that I don't like about Oracle's .Net Library is that sometimes you want more than the reader, but less than the DataAdapter.... So here is my little function to grab a reader and then return it as a data table. It returns nothing if there is nothing return


Function GetReaderAsDataTable(ByVal sql As String, ByVal Envrionment As String, Optional ByRef OtherOraConnection As OracleConnection = Nothing) As DataTable
 Try
   Dim OutputDataTable As New DataTable
   Dim x As Integer
  
   Dim cmdfunc As New OracleCommand
  
   If OtherOraConnection Is Nothing Then
    Me.ConnectToOracle(Envrionment)
    cmdfunc.Connection = mbiUser_Admin.OracleFunctionlib.oraConnection
   Else
    cmdfunc.Connection = OtherOraConnection
   End If
  
   cmdfunc.CommandText = sql
   cmdfunc.CommandType = CommandType.Text
  
   Dim drFunc As OracleDataReader
   drFunc = cmdfunc.ExecuteReader
  
  
   If Not drFunc.HasRows Then
    Return Nothing
   Else
    Dim DataRowString(drFunc.FieldCount - 1)
    For x = 0 To drFunc.FieldCount - 1
     OutputDataTable.Columns.Add(drFunc.GetName(x), drFunc.GetFieldType(x))
    Next
    While drFunc.Read
     For x = 0 To drFunc.FieldCount - 1
      DataRowString(x) = drFunc(x)
     Next
     OutputDataTable.LoadDataRow(DataRowString, True)
    End While
  
    Return OutputDataTable
   End If
  
  Catch ex As Exception
   Try
    HttpContext.Current.Session("msg") = (ex.Message & vbLf & vbCr & sql)
   Catch ex1 As Exception
    'Not in a HTTP Session; you can do something with the msg if you want... like return it to the user would be nice... but with most of my stuff just knowing that the sql didn't return anything is good enough. Robust, no, but usable.
   End Try
  
   Return Nothing
  End Try
  
  
End Function

Monday, September 1, 2008

Check an E-mail address with VB.NET Regex

This is a VB.NET Function to Check an e-mail address with Regex...

Function CheckValidEmail(Optional ByVal inputEmail As String = Nothing) As Boolean
If inputEmail Is Nothing Then
Return (False)
End If
Dim strRegex As String = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + "\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + ".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
Dim re As Regex = New Regex(strRegex)
If re.IsMatch(inputEmail) Then
Return (True)
Else
Return (False)
End If

End Function
Add to Google