Challenge of Day

Monday, February 14, 2011

How to convert a string XML to data type XML in Visual Basic VB .NET

It is quite common to convert a file containing an XML content to XML data type and then other ADO .NET objects.
Here is a sample program:

dim x as XMLReader
dim s as String

x = XMLReader.create("c:\baridsoft\orders.xml")

Now you can play with object "x" and manipulate it using Readxxxx methods. But the question is that most of the times you have your XML in memory with a string presentation.

Dim sr As New System.IO.StringReader("ali khademi20")
Dim xx As New Xml.XmlTextReader(sr)
xx = XmlReader.Create(sr)

Here is a sample program that is supposed to convert string to XML but it will trap in exception:
Unable to cast object of type 'System.Xml.XmlTextReaderImpl' to type 'System.Xml.XmlTextReader'.

Here is the solution to this problem:

Dim sr As New StringReader("ali khademi20")
Dim xx As New Xml.XmlTextReader(sr)

Be a winner in your daily challenges
Ali Khademi

Labels: , ,

Friday, November 19, 2010

DataSet.GetXML Does Not Return Null Values

XML is the defacto of data exchange and is used heavily as a means for presenting and transfering the data.
.NET framework provides a lot of facilities for manipulaitng this data type but when it comes to representing a data set with XML, .NET framework simply does not includes fields by null values. In other word, null fields are omitted in the output XML.
This is a known issue and you can read about it in this knowledgebase article by Microsoft.
There are two possible solutions to this problem:
1 - Either modify your SELECT statement and replace NULL values in the result set with some other values (e.g. Blank or Zero)
2 - You have to write your own GetXML method like this: This code snippet retrieves result set from a stored procedure and makes the XML string.

Dim conn As New OracleConnection
conn.ConnectionString = "data source=oracle;user id=baridsoft;pwd=barid"
Dim ds As New DataSet
Dim da As New OracleDataAdapter
Dim cmd As New OracleCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "sp_stored_procedure"
Dim p1 As OracleParameter
p1 = cmd.Parameters.Add("grs", OracleType.Cursor)
p1.Direction = ParameterDirection.Output
cmd.Connection = conn
da.SelectCommand = cmd
da.Fill(ds, "mytbl")
If ds.Tables.Contains("mytbl") Then
ds.Tables("mytbl").WriteXml("c:\ali\prr1.xml", XmlWriteMode.IgnoreSchema, True)
Dim strXML As String = ""
strXML = "" + vbCrLf
For Each r As DataRow In ds.Tables("mytbl").Rows
strXML = strXML + "" + vbCrLf
Dim st As String = ""
For i As Integer = 0 To r.ItemArray.Count - 1
st = st + "<" + ds.Tables("mytbl").Columns(i).ColumnName + ">"
If r.IsNull(i) Then
st = st + r(i).ToString
End If
st = st + "" + vbCrLf
strXML = strXML + st + "" + vbCrLf
Next strXML = strXML + "" + vbCrLf
End If

Be a winner in your daily challenges
Ali Khademi

Labels: ,

Thursday, October 14, 2010

Dr. Kordi Shoes

This is an attemp to run a shoes company web site. You can view it at

Be a winner in daily challenges
Ali Khademi

Tuesday, July 13, 2010

System.Data.OracleClient Requires Oracle Client Software Version 8.1 or Later

Couple of days ago, I was asked to make some enhancements to an old Visual Basic .NET program developed by Visual Studio 2003.
After upgrading the application and doing some refactoring, I replaced the (old) ADODB wrapper with System.Data.OracleClient.
The deployment environment is Windows 2000 Server which was updated with latest Microsoft patches including Service Pack and .NET Framework 3.5
After deploying the new program, it started to generate this error message:

System.Data.OracleClient Requires Oracle Client Software Version 8.1 or Later

It was very strand because the computer was running Oracle client 9.1 already.

I tried Oracle's Metalink knowledgebase. The closest shot (ID 1097598.1) stated this problem statement:

The following error may display when starting Performance Management Architect (EPMA) services on an Oracle database:"Service cannot be started. System.Exception: System.Data.OracleClient requires Oracle client software version 8.1.7 or greater."

And this document suggests this approach:

1- Log on to the MS Windows machine with the Administrator account.
2- Start MS Windows Explorer.
3- Navigate to the directory: ORACLE_HOME folder.
4- Right Click and choose the properties on the ORACLE_HOME folder.
5- Click the Security tab of the Properties window.
6- Click on the Authenticated Users in the Name list.
7- Uncheck the Read and Execute box in the Permissions list under the Allow column.
8- Recheck the Read and Execute box again.
9- Click the Advanced button.
10- In Permission Entries verify that Authenticated Users are listed with permission set to Read & Execute and Apply to set to: This folder ORACLE_HOME, subfolders and files.
11- Click OK to exit the security properties windows.
12- Restart the computer to ensure the changes take effect.

I followed above instructions but it did not solve my problem.

I also tried different recipes on the internet. Most of them suggesting similar solutions which was not helpful for me.

My workaround:

Finally I decided to upgrade Oracle Client from 9.1 to 9.2 and it worked successfully. To do so,
1 - I uninstalled the Oracle client by using Oracle Universal Installer.
2 - I went through all the Windows Registry (RegEdit.EXE) and cleaned all the entries were created by Oracle
3 - I restarted the computer
4 - I removed all the remaining Oracle files and folders from Windows Explorer including the one under "Program Files" folder and also OCI.DLL
5 - I installed new Oracle client program.

Be a winner in your daily challenges

Ali Khademi

Labels: ,

Wednesday, November 4, 2009

ISA (Internet Security and Acceleration) Blocks Outlook's POP3 and SMTP Mail Accounts

It is quite possible that your computer resides in a protected network, behind a proxy (MS ISA or Intenet Security and Acceleration) and you want to use our Microsoft Outlook to receive your emails from your POP3 mail server. In this case you might receive error 0x80090040 or 0x80042108 telling you Outlook cannot find your server or cannot connect to your POP3.
To work around this, 3 steps should be done:
1 - Make sure POP3, SMPTP and DNS protocols are open on your ISA. For this you should have an access rule allowing those 3 protocols from INTERNAL NETWORK to EXTERNAL NETWORK.
2 - Open the Microsoft Internet Security and Acceleration Server management console, expand the server name and the expand the Configuration node then click on the General node. In the General node, click on the Define Firewall Client Settings link in the Details pane. In the Firewall Client Settings dialog box, click the Application Settings tab. Pickup Outlook and change Key Value of Disbale to 0

3 - On your local computer, reconfigure your ISA client to refresh its local cache. Make sure firewall client on your computer is enabled as it is responsible to route your requests to ISA server.

Now restart your Outlook and try send or receive again. I assume that you have correct configuration for your email account.

Be a Winner in Your Daily Challenges.

Ali Khademi

Labels: , , , , , ,

Calling Oracle Stored Procedure from VB .NET

Calling Oracle Stored Procedure from VB .NET is not something new but since a Don from Cartersville asked me this question, I will explain it here. In general here is the source code to perfome this task:

Public Sub CallOracleStoreProceudre()
Dim conn As New OracleConnection("data source=baridsoft;user id=ali, pwd=khademi")
Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "OracleSP"
Dim p1 As OracleParameter
Dim p2 As OracleParameter

p1 = cmd.Parameters.Add("Param1", OracleType.NVarChar)
p1.Value = "Value1"
p2 = cmd.Parameters.Add("Param2", OracleType.Double)
p2.Value = 10


Catch ex As Exception
'Handle exceptions here
End Try
End Sub

This VB .NET subroutine calls OracleSP which accepts 2 parameters. It is quite possible to return a result set to calling subroutine. To do so replace the call to
cmd.ExecuteNonQuery with this line:

dim r as new SqlDataReader = cmd.ExecuteReader()

Then you can iterate through your data and process it. (like below)
' Do what ever you want
end while

ADO .NET has got wonderfull capabilities when coming to RESTfull data sources. I will cover it sometimes latter.

Here is an example of calling Oracle Stored Function as well:

Public Sub CallOracleStoredFunction()
Dim conn As New OracleConnection("data source=BaridSoft;user id=Ali Khademi;pwd=DoNotAskDoNotTell")
Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "sf_my_function"
Dim p1 As OracleParameter
Dim p2 As OracleParameter
Dim p3 As OracleParameter
Dim p4 As OracleParameter

p1 = cmd.Parameters.Add("param1", OracleType.NVarChar)
p1.Value = "123456"
p2 = cmd.Parameters.Add("param2", OracleType.NVarChar)
p2.Value = "Mn"
p3 = cmd.Parameters.Add("param3", OracleType.Number)
p3.Value = 10
p4 = cmd.Parameters.Add("v", OracleType.Int16)
p4.Direction = ParameterDirection.ReturnValue
Dim n As Integer
n = cmd.ExecuteNonQuery()
MsgBox("Function successfully executed. Return value is " + p4.Value.ToString, MsgBoxStyle.OkOnly, "Function Call")
Catch ex As Exception
' handle exceptions here
End Try
End Sub

Be a winner in your daily challenges

Ali Khademi

Tuesday, October 27, 2009

PowerBuilder 12 Beta 2 Presentation by Sybex

Today I watched the live official webcast about PowerBuilder 12 Beta 2 by Sybex company. For a long time developers were waiting about this event to see what is new in PowerBuilder 12.
First interesting point to my eyes is the estimated launch time of this product which will be second quarter 2010 which is almost 8 month from now. It means that whatever was presented today, was just a prototype.
I believe Sybex decided to support .NET platform because it was not successful in its Java targets (Tiger) in previous versions of PowerBuilder. Sybex could not find its place in the community of Java Open Source developers and could not impress the technology with its products and as a result, they decided to return back to Microsoft managed code platform.
Based on the presentation, they have just created a PowerBuilder to C# translator and then they call C# compiler from Visual Studio to generate managed code. I think they would have better just create a compiler for PowerScript.
They do not support compact framework, LINQ, Silverlight and many other new feathers in the framework and based my experience from PowerBuilder, in the same way that previous version was not integrated thightly with Java technology, the new generation will not be integrated with .NET framework.
At the end I have pasted list of question and answeres from technical team. It will help you realize more about this product.

Be a winner in your daily challenges
Ali Khademi

+++++++++++++ Here is the questions and answers from live cast +++++++++++++++++++++++++

Question: Migration of a PFC app to .net is possible now? It was not in beta 1.
Answer: I believe the runtime team has been able to migrate some PFC apps
Question: Can we get a copy of this PowerPoint somehow?
Answer: Yes, please send me your email address at and I will follow up with you
Question: what does wpf stand for
Answer: Windows Presentation Foundation (a TM of Microsoft)
Question: PB code is migrated to .NET. does that mean it will generate C# or other .NET app code? or it will still be a PB code (PB Script)
Answer: THere is an intermediate generation of C#, and that is compiled. You still code in PowerScript and XAML
Question: What is the future of Datawindow.Net?
Answer: We are going to evaluate the product after we deliver PB 12 to market. All of our engineering resources have been reallocated to working on v12 as it is such a significant release.
Question: Will the behavior of PB WPF controls be made more consistent with standard WPF controls? (ie: auto-resizing)
Answer: PB WPF controls are inherited from std WPF controls, and so support the same behavior...the difference you may be seeing is in the set of properties generated for the PB controls. You can change the width and height to "auto" to get auto-resize
Question: Can PB.NET WPF windows be integrated into a standard WPF .NET application (in Visual Studio)?
Answer: I am not sure I understand the question - if you are asking if you can develop parts of an application in PB and parts in VS, the answer is yes. PB builds and deploys .NET code.
Question: Can we open ancestor and child object at the same time? Was not it better that you just supply your PB# compiler instead of your ide?
Private Answer: This was just answered...
Question: will we be able to import datawindow at runtime from syntax stored in database in WPF mode?
Answer: yes
Question: will PB(Power Script) be added as a separat (NEW) language for .NET development? like PB.NET / C# . NET?
Answer: If you're asking if it wil be added to Visual Studio, the are not plans at the current time to do so.
Question: but it will be similar to C#/.NET?
Answer: It will produce managed code like any other .net language and can communicate with any .net language, which is the point of having different languages all run in the CLR. We don't want to change powerbuilder's language because that is what makes developing in PowerBuilder so simple! And, unlike MSOFT or any other vendor, we are protecting our customers' existing investment in code, and not going to make them learn a new language.
Question: Any enhancement to the source control interface? Automated build scripts (pull a PB application from source control by date/label and build it purely from what's in the repository) are currently very difficult. (Using TFS here)
Answer: Our goal is to support what VS has in the shell, including TFS in the future. For now, we still provide support to source code control via the MS SCC interface.
Question: I guess to clarify my question further can you launch PB WPF windows stored in a PB target (assembly) from a master WPF application written in C# easily?
Answer: Unfortunately, this is not a use case we've looked at.
Question: Books availalbe for PB 11.5 or PB 12????
Answer: There are lots of online tutorials and samples being created for learning these releases.
Question: When the pocket powerbuilder with CE .NET framework is available?
Answer: We currently don't have a schedule for delivering this support. Like with DW .NET, we are waiting until we are ready to deliver v12, and will then re-evaluate the product roadmap at that time. Part of the challenge is waiting to see what MSOFT delivers for Windows Mobile 7. Ultimately, we want mobile targets inside of PowerBuilder and customers should be able to leverage existing PocketBuilder code and bring it back inside of PowerBuilder
Question: You have not looked at it from the standpoint of trying it or it will not work? We have a lot of legacy PB code and new C# .NET WPF code. We are looking to migrate our PB Classic code to PB.NET and I am wondering if it is possible?
Answer: I may have misunderstood your original question - it won't be like C# in that we aren't changing the way you code in PowerBuilder. Our intent is to help you migrate as much of your PowerBuilder Win32 code to WPF - so I think we are planning to do just what you're looking for. The migration utility is something we'd like you to test in beta.
Question: Will this presentation be available for download?
Answer: send me an email at and I will get it to you
Question: is the application developed and deployed from PB12 managed code?
Answer: Yes, it's managed code.
Question: Is the Beta 2 Release/Upgrade the same as the “Beta 2 Refresh” or are all the updates referred for the “Beta 2 Refresh”, a release/upgrade planned for after the Beta 2 Release/Upgrade?
Answer: So beta 2 is different from the beta 2 refresh. the refresh is as you expected, bug fixes and CRs to the beta 2 software release
Question: Can we say in order to get best of .NET framework, we have to rewrite our legacy PB program again?
Answer: It really depends upon how well your application is written. Our goal is to make leveraging .NET as easy as possible, which is why we have a migration utility to bring your Win32 code to .NET. If you've written a well partitioned application, and you now would like to leverage services available in the .NET framework, you should be able to do so with relative ease. It's hard to answer because people build so many different types of applications with different coding styles.
Question: Does Beta 2 work with VS 10 Beta ?
Answer: We are building PowerBuilder on top of the shell so you wouldn't use Visual Studio with PowerBuilder.
Question: Will there be support for PFC migration? Or should we scrap PFC and re-write?
Answer: Engineering is migrationg PFC applications during the development process and will be documenting the process and we will make this available in a "how -to" doc format for customers before GA.
Question: will PB still be generating PCode when compiling the objects?
Answer: PB.NET translates to C# as an intermediate step, and that C# is compiled directly to the CLR. There is no PCode with WPF targets.
Question: Future - How long will Sybase continue support for the “Classic” IDE, in reference to PB 12 .Net vs PB 12 Classic? What is Sybase’s direction/mission/vision in this matter?
Answer: We don't have any plans to discontinue any support for Win32. Our current plans are to support version 12 as a complete release, that is, we will support it in the same fashion that we have done in the past for all other releases, it will have a specific lifetime. But, I think Win32 is at the root of your question, and MS does not have plans to discontinue support for Win32 applications, and we will continue to follow their lead in this area.
Question: It is possible to build a Mixed solution where some of the projects are developed in ant others in VS 10 ?
Answer: Yes
Question: I will try my question a different way. If we have an existing C# WPF application that is written in Visual Studio, can we integrate windows created in PB.NET (in order to leverage our legacy PB Classic code that was ported to PB.NET)? More specifically, could we launch a PB.NET window from a menu (or action) inside of a C# WPF application written in Visual Studio? This way we can integrate the two environments seemlessly to the end user.
Answer: The short answer is this is not supported.
Question: Do you support Silverlight as well?
Answer: We will be providing support in a future release - MSOFT is adding an IDE for Silverlight support in their next release of VS.
Question: May I have a copy of slides of today's presentation?
Answer: Send me an email at for the slides
Question: What prevents it from being supported (calling PB.NET WPF windows from an action written in a C# WPF application)? This is critical to our integration of multiple environments.
Answer: The only scenario we currently support for deploying PB objects and using them from another .NET language is the .NET Assembly target, and in that case I believe we are only supporting non-visual objects. While
Question: Does Sybase have plans to support deploying applications as SilverLight?
Answer: That is our current plan for a release post -v12.
Question: I can export dw to PDF without ghostscript
Answer: We are supporting MSOFTs implementation of PDF
Question: What is the target release date for PB12?
Answer: Currently it's in the latter part of the first half of 2010. Likley Q2 2010
Question: Are there 2 types of richTextedit datawindows in PB 12 or only the WPF type?
Answer: There is support in both WPF and Classic but they have different providers; in Win32 we have a specific OEM control built into the product and in WPF we use WPF natively.
Question: For 2010 budget planning - Currently we are planning to continue in your PB 12 .Net Beta program, while maintaining our PB 9.0 development environment. What will be the basic/base cost in 2010, for old classic PB developers to make this leap?
Answer: It would simply be the cost of new development licenses for v12 - $2995/seat is the list price.
Question: Can you use standard .NET WPF controls inside of PB.NET or do you have to use ALL of the PB.NET WPF controls?
Answer: You can use both.
Question: Do we have support for LINQ? Is PB 12 IDE is extensible?
Answer: LINQ is not supported in 12. The PB.NET IDE is extensible, but it depends, so let us know what specifically you have in mind.
Question: are there runtime licensing fees for 12.0?
Answer: No, only developer licenses.
Question: How can I use DataWindow in a VB program?
Answer: DataWindow .NET is available as a plugin for Visual Studio.
Question: For future budget planning - Once a new PB v12 .Net development licenses has been purchased (“$2995/seat is the list price”), what will be the annual maintenance costs?
Answer: The best deal is to purchase a USP (upgrade subscription @$645 annually.) This will give you a new release if it is delivered within 12 months of your purchase, and you can renew it annually for the same fee; two years of USP is still less than an update license. There are other options available for support.
Question: Is PB 12 supported on 64-bit Windows OS during the beta?
Answer: yes, for deployment
Question: what about 64-bit support for the development environment?
Answer: It will likely run but it is not something we test.
Question: going to the xml-fo, now that pb 12 can create pdf without ghostscript, can i feed it xml-fo and have it create a pdf file, i.e. acting like a fop
Answer: Likely not - the FOP processor is Java-based, while PB12's PDF generation is using the .NET Framework.
Question: is the .net framework required for pb 12
Answer: Yes, 3.5, but we redistribute.
Question: Is multi-threading supported in PB12?
Answer: I don't believe there is anything preventing you from using the .NET Framework Thread object within PowerScript. It should translate during our 'pb2cs' compile.