Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
13
Erster Beitrag:
vor 6 Jahren, 10 Monaten
Letzter Beitrag:
vor 6 Jahren, 10 Monaten
Beteiligte Autoren:
Jeff Graham, Arie, DW, Art Bonds

C# example in WD16 and OleDbConnect in C#

Startbeitrag von Jeff Graham am 30.08.2011 22:53

PC Soft just pointed out to me the External Languages\C# City example that shows how to call WinDev from C#. This may be useful for my finger scanner C# project that keeps hitting brick walls! However the data access is done in WinDev and the C# classes are in French.

What I am trying to do is just connect to HF through OleDb from C#:

try
{
System.Data.OleDb.OleDbConnection myOleDb = new System.Data.OleDb.OleDbConnection
("Provider=PCSOFT.HFSQL;Initial Catalog=D:\\BioMetrics\\VF_CS_Test\\Exe\\Fingerprints");
myOleDb.Open();
... Data access code
// Close
MyData.Close();
myOleDb.Close();

}
catch(Exception ex)
{
textOLE.AppendText("Error in connect: \n" + ex.Message);
}


I get an error on the Open:
No error message available, result code: E_FAIL(0x80004005).

I suspect the connection string is not correct but the format is from the WinDev help (OLE DB provider for HyperFile SQL). I can't find more information. PC Soft just refers me to the City example.

Has anyone connected to HF from C#?

Thanks,

Antworten:

Hi Jeff,
I have a VB.NET webservice running, connecting to a HFCS database. Here is some code:


Dim Hfcs As New Hyperfiles
Hfcs.LogInfo(sProcess, sInfo, nType)


"Hyperfiles" is a homebrewed class - paste the code below in a file called Hyperfiles.vb and include it in your project


Imports System.Data.OleDb
Imports System.IO

Public Class Hyperfiles
Dim sAppPath As String
Dim sHost As String
Dim sDatabase As String
Dim sUser As String
Dim sPassword As String
Dim ourConnection As OleDbConnection
' Dim sCustomerID As String

Public Sub New()
Dim myIni As New IniFiles
sAppPath = HttpContext.Current.Request.PhysicalApplicationPath
sHost = myIni.ReadIni(sAppPath + "InstallationService.ini", "DATABASE", "HOSTNAME", "LOCALHOST:4900")
sDatabase = myIni.ReadIni(sAppPath + "InstallationService.ini", "DATABASE", "DATABASE", "KlusBox")
sUser = myIni.ReadIni(sAppPath + "InstallationService.ini", "DATABASE", "USER", "ADMIN")
sPassword = myIni.ReadIni(sAppPath + "InstallationService.ini", "DATABASE", "PASSWORD", "")
' sCustomerID = myIni.ReadIni(sAppPath + "InstallationService.ini", "DATABASE", "CUSTOMERID", "1")
ourConnection = New OleDbConnection("Provider=PCSoft.hfsql;" & "Data Source=" & sHost & ";Initial Catalog=" & sDatabase & ";User Id=" & sUser & ";Password=" & sPassword & ";")
End Sub


Public Function LogInfo(ByVal sProcess As String, ByVal sInfo As String, ByVal nType As Integer)

Dim sqlCommand As New OleDb.OleDbCommand
Dim Now As DateTime
Now = DateTime.Now

Try
sqlCommand.CommandText = "INSERT INTO tbl_logbook (description,creationdate,creationtime,code,process,logbooktypesid) VALUES(" &
"'" + sInfo + "'," &
"'" + Now.ToString("yyyyMMdd") + "'," &
"'" + Now.ToString("HHmmss") + "'," &
"'" + CStr(0) + "'," &
"'" + sProcess + "'," &
"'" + CStr(nType) + "')"
sqlCommand.Connection = ourConnection
sqlCommand.Connection.Open()
sqlCommand.ExecuteNonQuery()
sqlCommand.Connection.Close()

Return True

Catch ex As Exception
Dim obj1 As StreamWriter
obj1 = New StreamWriter(sAppPath + "error.log", True)
obj1.WriteLine(sProcess + " " + Now.ToString("yyyyMMdd_hhmmss") + " : " + ex.Message)
obj1.Close()
Return False
End Try

End Function

Public Function SaveXml(ByVal sXml As String, ByVal sRef As String, ByVal sContractorID As String, ByVal nStatus As Integer, ByVal nAction As Integer)

Dim sqlCommand As New OleDb.OleDbCommand
Dim Now As DateTime
Now = DateTime.Now

Try
sqlCommand.CommandText = "INSERT INTO tbl_syncdata (Incoming,IncomingDatetime,IncomingReference,IncomingText,IncomingFile,RelatieID,SyncAction,Status) VALUES(" &
"'" + CStr(1) + "'," &
"'" + Now.ToString("yyyyMMddHHmmss") + "'," &
"'" + sRef + "'," &
"'" + sXml.Replace("'", "''") + "'," &
"'" + "" + "'," &
"'" + sContractorID + "'," &
"'" + CStr(nAction) + "'," &
"'" + CStr(nStatus) + "')"
sqlCommand.Connection = ourConnection
sqlCommand.Connection.Open()
sqlCommand.ExecuteNonQuery()
sqlCommand.Connection.Close()

Return True

Catch ex As Exception
Dim obj1 As StreamWriter
obj1 = New StreamWriter(sAppPath + "error.log", True)
obj1.WriteLine("SaveXml " + Now.ToString("yyyyMMdd_hhmmss") + " : " + ex.Message)
obj1.Close()
Return False
End Try

End Function

End Class







von Arie - am 31.08.2011 07:59
Hi Arie,

Thanks for the code. This helps a lot. I also just received my .Net reference books that will assist my learning.

Cheers,

von Jeff Graham - am 31.08.2011 16:43
Jeff,
if you are a .NET newbie, I would use VB instead of C#.
It's much more close to the WD-syntax. With the exact same results.


von Arie - am 31.08.2011 17:35
Have you seen this one?

http://www.griaulebiometrics.com/en-us/fingerprint_sdk

I haven't looked at it hard yet, just passing it on for reference.

von Art Bonds - am 03.09.2011 15:50
Hi Art,

If you are looking for biometric solutions, here is the one I am using:
http://www.neurotechnology.com

Their support is excellent and they were recommended by http://www.fulcrumbiometrics.com/

We have been using an older version for over 5 years with excellent results. Many finger scanners do not work well with small fingers of elementary school children. The free Digital Persona for example.

Thanks for the link,

von Jeff Graham - am 03.09.2011 16:28
More on C# saga,

Quote
PC Soft
I have checked with our developers? Unfortunately using C# you cannot connect directly to HyperFileSQL, you need to use the WLanguage for that.

This is now a suggestion for a future release, #73 173/356275. Please use this reference when contacting me upon this matter . I'll keep you posted.

Note that you could build a DotNet assembly using WINDEV in order to access your data.


Does anyone have an example of creating a WD .Net assembly and then using it in C#? I am stumbling my way through this and would greatly appreciate any ideas. I want to read and write one table with 4 fields, one of which is a binary.

Thanks,

von Jeff Graham - am 06.09.2011 20:16
Jeff,
what is the problem doing it the other way round.
Write C# (or VB) code in .NET and use the oledb-driver from pcsoft, to get access to your data. As mentioned above in my previous post. It works for me.

Maybe it doesn't support blob-fields?


von Arie - am 07.09.2011 08:04
Hi Arie,

I am able to use your method to add all the simple fields, AccountsID, etc. However I can't figure out how to add non-text fields (private byte[] _template) as binary with the insert command. Parameters are not supported by PC Soft's OLEDB. Otherwise, it would work.

PC Soft specializes in the "short answer" so maybe there is a way. Because creating a .Net assembly and using it in .NET is not straight forward to me. I have asked for an example, but I just got a response that none exists (suggestion registered).

So far my approaches to interface with Neurotec:
1) Use their .NET assemblies in WinDev -> crashes WDTst.exe (reproduced problem).]
2) Use OleDbCommand -> How to store bye[]?
3) Use OleDbDataAdapter -> not supported (registered suggestion to support)
4) Create .NET assembly in WD to use in C# -> current testing (no example)

Somehow, I don't think there are many English users of .NET and WinDev. I appreciate your help, Arie. The saga continues.

von Jeff Graham - am 07.09.2011 13:51
Hello Jeff,

I have limited experience with dot net also, but was able to create a .net assemble in Windev that allowed C# app to write to a HF classic data file.

In a nut shell create a Windev project with everything that you need to read and write to the data file including the connection (All Global Procedures). Compile it as a .net assembly and then you can use the procedures as .net

You must read the help there are other dll that need to be included in your C# app like the Windev.cs and reference the class using WL;

That is all I can offer good luck.

DW

von DW - am 08.09.2011 00:35
Hi DW,

That is really encouraging! I will pursue this approach aggressively.

Is there any way you could share some of your code?

Cheers,

von Jeff Graham - am 08.09.2011 14:02
Hello Jeff,

I could email you a link to the project for download.

DW

von DW - am 08.09.2011 20:34
Hi DW,

Your hints got me to the first step success. However, as I am a .NET newbie, a sample would be great. You can email me at jeff (at) accmeals dot com.

I will try to use that to package a WD and C# example to post on the solutions forum.

Thanks,

von Jeff Graham - am 09.09.2011 13:48
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.