C# server = a server written in C#
it uses a combination of TCPListener,network stream and binaryreader and writer to talk to client. Any ideas if these exsist in java?
jonnytabpni 0 Light Poster
jonnytabpni 0 Light Poster
Hi folks,
I've got a C# client which can currently communicate with a C# server.
I am considering re-writing the server in Java (to make it work better on Linux).
Currently, the C# setup uses BinaryReader/Writer on top of a Network Stream on top of a Socket.
Is there some Java implementation that would be compatible with the C# end?
If not, what should I change? I'm hopeing I don't have to deal with raw Socket data.....
Cheers :)
Jonny
jonnytabpni 0 Light Poster
Hey folks,
I've been reading:
http://www.codeproject.com/KB/IP/cs_remoting.aspx
Now, I havn't actually done anything in the article yet however a question springs to mind.
I have an app that has non-decoupled UI and business stuff (probably not the best). In time, I would like to make this app run on a "Software as a Service" model.
I woudn't mind having a "thin app" run on a client machine, which launches the real UI from a remote server via .NET remoting.
Now, what I am confused about is that in the above web link, you have to referance the "Remote Object" in the client app (in my case the "thin app"). To me, this means that I would have to includes the WHOLE server code in the "thin app" which defeats the purpose of the app being thin.
This gets very confusing for me.
How would I go about such a feat? Just generally speaking anyways. Would I have to deal with interfaces somewhere?
Thanks for your help and if something isn't clear, please ask as I understand that my question maybe very poorly written.
Thanks
Jonny
jonnytabpni 0 Light Poster
ok sure,
My aim is to get the till to send an XML file (which I call a TRN) of the transaction just processed to the server. This allows "real-time" stats as well as refunds from other tills (If, for example the refund system was complex and needed a receipt scanned or something).
Now, at the "End of Day", the till will still do a proper sync and verify (Whether that be by syncing databases or re-sending all the xml files again in a zipped file I havn't decided yet).
The sending of the TRN after each transaction is just an added feature really.
Let me know if oyu need further details. I really appreciate your help.
Jonny
P.S. I took your suggestion above about processing the directory at the end of each transaction and seems to do the trick
jonnytabpni 0 Light Poster
the till actually doe have a local database store however I guess I'm not using it effectivly.
Could you maybe elabroate further on this please? That would be great :)
I started writing a method which looks like this:
public void start()
{
while (true)
{
string[] files = Directory.GetFiles(@".\TRN\", "*.xml");
foreach (string filename in files)
{
string s = System.IO.File.ReadAllText(filename);
try
{
lock (Network.writer)
{
Network.writer.Write(s);
//Add some code here to delete the current file if sending sucessful
}
}
catch
{
}
}
}
}
Thanks
jonnytabpni 0 Light Poster
Hi folks,
I have a Client (A Till) and a server which I am developing in C#.
I wish to implement some sort of network queuing system. So basically, when a method wants to send some data to the server, it will try first and if it fails, then add it to a "queue" and try to send x seconds again later.
Generally, the data which is being sent to the server is 2 strings, on after the other. The first being an id of some sort, the next being a string which is formatted in XML.
It would be nice if this queue could survive a termination of the application.
Any ideas on how to implement such a thing? Maybe I'm going about this a completly wrong way?
I have this idea of saving the xml files to the hard drive in a queue folder and having a thread constantly running in the background to check for files in this folder and try to send them to the server. Maye there is a better way for this?
Thanks for the help :)
Jonny
jonnytabpni 0 Light Poster
Hi folks,
I'm currently trying to send data from a client to a server. It is an xml file.
The client has this code:
public void sendXML(XmlDocument xdoc)
{
try
{
//Using the network stream to send data
NetworkStream nts = new NetworkStream(Network.m_clientSocket);
xdoc.Save(nts);
nts.Flush();
}
catch
{
Connected = false;
}
}
and the server has code like this:
public void Start()
{
NetworkStream nStream;
string data;
tcpListener.Start();
TcpClient tcpClient = tcpListener.AcceptTcpClient();
nStream = tcpClient.GetStream();
while (true)
{
byte[] buffer = new byte[1024];
//Read from the Network Stream into buffer
nStream.Read(buffer, 0, buffer.Length);
while (nStream.DataAvailable)
{
nStream.Read(buffer, 0, buffer.Length);
}
//Convert buffer into string
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
data = enc.GetString(buffer);
this.CheckData(data);
}
}
The problem lies in the fact that the xml file is being split up into 2 reads of the network stream meaning that the CheckData method isn't getting the whole file at once.
How would I go about fixing this?
Thanks for the help :)
jonnytabpni 0 Light Poster
Hi Folks,
I'm using this code I found online to decompress a large file. It works fine when I try it with a small file i.e. a 5MB mp3 (1.7MB compressed) but when I try and use it with a 250MB file (27MB compressed), the newly created output file is the same size as the input compressed file (AFAIK, it is probably a copy). I have tried this on a machine with 256MB of RAM and a machine with 4GB of RAM...
protected void Decompress(string filePath,string fileout)
{
FileStream sourceFile = File.OpenRead(filePath);
FileStream destinationFile = File.Create(fileout);
GZipStream unzip = null;
byte[] buffer = new byte[sourceFile.Length];
try
{
unzip = new GZipStream(sourceFile, CompressionMode.Decompress, false);
int numberOfBytes = unzip.Read(buffer, 0, buffer.Length);
destinationFile.Write(buffer, 0, numberOfBytes);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sourceFile.Close();
destinationFile.Close();
unzip.Close();
}
}
Your help is appreciated.
Thanks
jonnytabpni 0 Light Poster
Thanks you very much! :) Works great
Just wondering though, do you reckon the above code is "more efficient" than creating another temp Iterator to go through all the items (Similar to what we did for the command node)?
Thanks
jonnytabpni 0 Light Poster
I've got this so far:
while (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
if (nav2.GetAttribute("commandName", "") == "opendrawer")
{
Device.drawerkick();
}
else if (nav2.GetAttribute("commandName", "") == "updateDatabase")
{
string desc = "";
string barcode = "";
string category = "";
string vatcode = "";
string price = "";
XPathNodeIterator temIterator = nav2.SelectDescendants(XPathNodeType.Element, false);
do
{
if (temIterator.Current.Name == "item")
{
while (temIterator.MoveNext() && temIterator.Current.Name != "item")
{
if (temIterator.Current.Name == "desc") desc = temIterator.Current.Value;
else if (temIterator.Current.Name == "barcode") barcode = temIterator.Current.Value;
else if (temIterator.Current.Name == "category") category = temIterator.Current.Value;
else if (temIterator.Current.Name == "vatcode") vatcode = temIterator.Current.Value;
else if (temIterator.Current.Name == "price") price = temIterator.Current.Value;
}
Remote.AddProduct(barcode, desc, category, vatcode, price);
}
} while (temIterator.MoveNext());
}
}
It only adds the first item in the XML file though :(
Where am I going wrong?
Thanks
jonnytabpni 0 Light Poster
The table structure may change in time (As different types of database may be used). The Remote.AddProduct method handles updating the table. Is it possible to use this? I'm trying to think of a way to make it check for different <item> nodes..
jonnytabpni 0 Light Poster
Hi There,
Thanks for your reply. It's very close to what I want. What I am actually doing is adding to a database and the problem I think with the above code is that it woudn't be able to do multiple <item> node update?
Here is my XML File:
<paypointXML>
<commands>
<command commandName="opendrawer">
</command>
<command commandName="updateDatabase">
<items>
<item>
<desc>Apple Computer</desc>
<barcode>5760</barcode>
<price>899.99</price>
<vatcode>1</vatcode>
<category>300</category>
</item>
<item>
<desc>Banana Computer</desc>
<barcode>5761</barcode>
<price>999.99</price>
<vatcode>1</vatcode>
<category>300</category>
</item>
</items>
</command>
</commands>
</paypointXML>
And here is my c#:
while (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
if (nav2.GetAttribute("commandName", "") == "opendrawer")
{
Device.drawerkick();
}
else if (nav2.GetAttribute("commandName", "") == "updateDatabase")
{
string desc = "";
string barcode = "";
string category = "";
string vatcode = "";
string price = "";
XPathNodeIterator temIterator = nav2.SelectDescendants(XPathNodeType.Element, false);
while (temIterator.MoveNext())
{
if (temIterator.Current.Name == "desc") desc = temIterator.Current.Value;
else if (temIterator.Current.Name == "barcode") barcode = temIterator.Current.Value;
else if (temIterator.Current.Name == "category") category = temIterator.Current.Value;
else if (temIterator.Current.Name == "vatcode") vatcode = temIterator.Current.Value;
else if (temIterator.Current.Name == "price") price = temIterator.Current.Value;
}
Remote.AddProduct(barcode, desc, category, vatcode, price);
}
}
How would I get it to acount for multiple item nodes? It is not guarenteed that all the elements of item will be present (i.e. someone may leave out category or vatcode etc...)
Thanks
jonnytabpni 0 Light Poster
OK, i have managed to find a way around my problem above however I've had to change my XML structure which I don't really like.
Here is the new XML layout:
<paypointXML>
<commands>
<command>opendrawer</command>
<command>updateDatabase</command>
</commands>
<items>
<item>
<desc>Big Book of Tales</desc>
<price>5.99</price>
<category>100</category>
</item>
<item>
<desc>Small book of Rhymes</desc>
<price>1.99</price>
<category>100</category>
</item>
</items>
</paypointXML>
and my c# method looks like this:
private void XMLHandler(string data)
{
XmlDocument tdoc = new XmlDocument();
tdoc.LoadXml(data);
StringReader str = new StringReader(data);
XPathDocument doc = new XPathDocument(str);
XPathNavigator nav = doc.CreateNavigator();
// Compile a standard XPath expression
XPathExpression expr;
expr = nav.Compile("/paypointXML/commands/command");
XPathNodeIterator iterator = nav.Select(expr);
// Iterate on the node set
try
{
while (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
if (nav2.Value == "opendrawer")
{
Device.drawerkick();
}
else if (nav2.Value == "updateDatabase")
{
foreach (XmlElement item in
tdoc.SelectNodes("/paypointXML/items/item"))
{
string desc = item.SelectSingleNode("desc").InnerText;
MessageBox.Show(desc);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
As you can see, I'm reading the XML file twice which probably isn't a good idea..
As you can see, I know next to nothing about XML!
Any ideas on how to make my code more efficient?
Your help is appreciated Thanks
jonnytabpni 0 Light Poster
Hi folks,
I'm trying to write an XMLHandler for my epos app. The XML file (which is received by a network stream) will include multiple "operations" which may include updating the product database or opening the cash drawer etc..
My sample XML file looks like this:
<paypointXML>
<op>
<command>opendrawer</command>
</op>
<op>
<command>updateDatabase</command>
<item>
<desc>Big Book of Tales</desc>
<price>5.99</price>
<category>100</category>
</item>
<item>
<desc>Small book of Rhymes</desc>
<price>1.99</price>
<category>100</category>
</item>
</op>
</paypointXML>
So far my c# code looks like this:
private void XMLHandler(string data)
{
StringReader str = new StringReader(data);
XPathDocument doc = new XPathDocument(str);
XPathNavigator nav = doc.CreateNavigator();
// Compile a standard XPath expression
XPathExpression expr;
expr = nav.Compile("/paypointXML/op/command");
XPathNodeIterator iterator = nav.Select(expr);
// Iterate on the node set
try
{
while (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
if (nav2.Value == "opendrawer")
{
Device.drawerkick();
}
else if (nav2.Value == "updateDatabase")
{
//I want this to iterate through all the nodes inside THIS paticular op node..
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Now, as you can see above my c# code will only ever parse the opendrawer command. I am lost when it comes through iterating through the current node...
Can anyone please help me on how to achieve the above with regarding update my database?
Maybe my XML file struct could be better? Maybe the item details should be inside the command node?
Your help is appreciated thanks
Jonny
jonnytabpni 0 Light Poster
OK folks, got this sorted.
It was actually another class (My listener class) in my epos app causing it to take up 100% of CPU time. All I needed to do was add a Thread.Sleep(100) to a infinate while loop
jonnytabpni 0 Light Poster
Ok so the suitation gets weirder. I have found out that during the time when my epos app is trying to connect to the server (hense also the time when to touchscreen won't work), the mouse CAN move if the "driver" Winform is in Focus (normally, it is minimised to the system tray..)
**UPDATE**
OK folks yet another update! If I put a Thread.Sleep(10) in my driver app just before the if statement, then it works just VERY slowly (Unuseable but hey, there's life!).
So some sort of system resource sharing between apps then?
Cheers
**UPATE**
And....another update! I feel so stupid! During the connect loop, my epos app is taking up 100% CPU! This must be the cause! Any ideas on what I'm doing wrong there? Thanks
jonnytabpni 0 Light Poster
Hi folks,
I have written 2 applications on my till running windows 2000. One is an epos system and the other is a "driver" which parses the text from the touch screen and moves the mouse accordingly.
I'm having a very strange issue. I have recently added network functionality to my epos app. There is a classwhich keeps retrying to connect to the server incase the network is down. What I find is that during this loop (which is run in a seperate thread from my epos app's main thread), my touchscreen driver just doesn't move the mouse or just crashes if you just wait long enough (circa 1 minute or so) with a Send/Don't Send style message "system.indexoutofrangeexception". Once the epos app connects to the server, the touch screen drivers works again (provided it hasn't crashed already...).
Here is my "connector" class used in the epos app:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
namespace Paypoint
{
class Connector
{
Network networkinterface;
IPEndPoint ipEnd;
public Connector(Network network, IPEndPoint endpoint)
{
networkinterface = network;
network.Connected = false;
ipEnd = endpoint;
}
public void Start()
{
while (true)
{
if (networkinterface.Connected == false)
{
networkinterface.initSocket();
connect();
}
Object objData = "ping";
byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString());
networkinterface.send("ping");
Thread.Sleep(2000);
}
}
private void connect()
{
while (!networkinterface.Connected)
{
try
{
Network.m_clientSocket.Connect(ipEnd);
networkinterface.Connected = true;
}
catch
{
networkinterface.Connected = false;
Thread.Sleep(10000);
}
}
}
}
}
Here is my TouchScreen …
jonnytabpni 0 Light Poster
Hi folks. I have some code which I'm trying to do network sockets with. My dev machine is Vista with C# Express 2008 and the target machine is running Windows 2000 (no visual studio)
Here is my Network class
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace Paypoint
{
public class Network
{
byte[] m_dataBuffer = new byte[10];
static string commandbuffer = "";
IAsyncResult m_result;
public AsyncCallback m_pfnCallBack;
public Socket m_clientSocket;
System.Threading.Thread newThread2;
IPEndPoint ipEnd;
public void init()
{
// Create the socket instance
m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Cet the remote IP address
IPAddress ip = IPAddress.Parse("10.87.0.13");
int iPortNo = System.Convert.ToInt16("2061");
// Create the end point
ipEnd = new IPEndPoint(ip, iPortNo);
// Connect to the remote host
connect(ipEnd);
if (m_clientSocket.Connected)
{
//Wait for data asynchronously
WaitForData();
}
}
private void connect(IPEndPoint ipEnd)
{
bool notConnected = true;
while (notConnected)
{
notConnected = false;
try
{
m_clientSocket.Connect(ipEnd);
}
catch (SocketException se)
{
notConnected = true;
}
}
}
void send(string data)
{
try
{
Object objData = data;
byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString());
if (m_clientSocket != null)
{
m_clientSocket.Send(byData);
}
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
}
}
public void WaitForData()
{
try
{
if (m_pfnCallBack == null)
{
m_pfnCallBack = new AsyncCallback(OnDataReceived);
}
SocketPacket theSocPkt = new SocketPacket();
theSocPkt.thisSocket = m_clientSocket;
// Start listening to the data asynchronously
m_result = m_clientSocket.BeginReceive(theSocPkt.dataBuffer,
0, theSocPkt.dataBuffer.Length,
SocketFlags.None,
m_pfnCallBack,
theSocPkt);
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
}
}
public class SocketPacket …
jonnytabpni 0 Light Poster
Hi folks,
I have an app that will connect to a server.
My connect method looks a bit like this:
private void connect(IPEndPoint ipEnd)
{
try
{
m_clientSocket.Connect(ipEnd);
}
catch
{
connect(ipEnd);
}
}
Now, if I run this, my application can't let the user still use it as it's stuck in this loop. So I tried putting the whole network class in a different thread. However, when I start the server, the client machine will bring up an error saying that the I/O opeartion has stoped due to a Thread exit or application request...
Any Ideas?
Thanks
jonnytabpni 0 Light Poster
hmm ok, as it turns out, i don't think its the serial port writing causing this. I forgot to mention that after the printing method is called, a few other methods are called to stores stuff to a Sqlite database (which is slow). I think it is this that's causing the problem.
Really, what I am looking for is just some tips on how to make sure that the Form is updated before all the rest happens.
Apperently just calling the method first doesn't do this :(
Cheers
jonnytabpni 0 Light Poster
Hi folks,
In my c# epos app, i have a method which does two things:
It calls a method to update the Form with the change to be given to the customer.
It then calls a method to print the receipt to the serial printer.
Even though the update Form method is called first, it doesn't get enough time to update the label for the change (Other labels appear half-updated). THe Form just seems to not update until the printing it over.
I have tried adding Thread.Sleep(10) to the method which does the printing but all this does is just delay the receipt printing....
Any ideas?
Thanks
jonnytabpni 0 Light Poster
by the way, i think I'm using completly wrong terms when I say "binary file". I think what I'm suppoed to say it "file with ESC/POS codes that outputs a bitmap"
jonnytabpni 0 Light Poster
this looks like it could do the job for me:
http://kseesharp.blogspot.com/2007/12/read-file-into-byte-array.html
I would have to put the number of byte of the file into the serielpor's Write method though
jonnytabpni 0 Light Poster
Hi guys,
No, this printer doesn't have on-board memory. Its the TM-T88ii (One mark below the version which does have memory).
I don't think I can put the BMP into a byte array as this "binary file" is in special Epson ESC/POS code so need to be sent.
Now, could i put the binary file into a byte array?
Cheers
jonnytabpni 0 Light Poster
Hey folks,
I have an Epson POS printer which support printing via my COM port using ESC/POS. This all works well in my c# app. I have used Epson's BMP converter tool to convert a bmp file to a binary file which can be sent directly to the printer.
How would I get my c# app to send this binary file straight to COM1?
I am familiar with the basic sp.Write("lalala") and sp.Writeline("lalala") commands.
The binary file is only 4kb in size so do I really need a binarystreamer? Can I not just do something like fopen(logo.dat,br) ??
Your help is appreciated thanks
jonnytabpni 0 Light Poster
Hi Jerry!
I really appreciate your help!
With regards to my method.dll, the way I'm doing it is similar to the second way you mentioned. I have 3 public classes inside modules.dll:
Payment
Discount
Sale
And each of these classes has 2 public methods:
init
callback.
All the other processing is within private method in modules.dll and the "production version" (or in my case the "dummy version"), init and callback for all 3 classes are just blank. For an idea of what the init and callback methods in the payment class does, please goto http://dl.abpni.co.uk/eft-1.jpg (please ignore the red boxes). The harder ones are the discount and sale classes.
The problem (which makes my code very messy), is the returns from these public methods inside modules.dll as I have to account for lot of future plugins.
I'm ready to get started with plugins if your willing to help me :) I really appreciated your willingness to help me get this going!
I'm a VERY messy coder. Everything is all over the place. Just learning really. If you promise not to laugh, I can even show you my code if your willing to take a look at it. I understand if you do not want to do this - I'm sure your time is precious.
Cheers,
Jonny
jonnytabpni 0 Light Poster
Hi Jerry,
Thanks for the great advice! I def want to go down this route. I will tell you what I'm currently doing now and you can either suggest that I scrap it or modify it.
My Form (I belive you call this an interface) has buttons. Hard Coded into the program are button types. Here is what I have so far:
0) Product
1) Tender
2) quantity
3) void
4) till menu
5) Payment Module
6) Refund
7) Sale Module
8) Discount Module
N.B. When you see module, this is located in my seperate "modules.dll".
I have a Sqlite database which has a buttonmap table. In it are these fields:
buttonid
buttontype
value1
value2
buttontext
At program launch, the Form will read this database and looking at the button id and button type, it can tell what to do with them.
So for example if its a refund, it will call the refund method. If it's a "payment module", it will call the modules.payment.init(int value1) method (located in the seperate dll). This dll, given whats in value1, will know that this is for, for example, a giftcard. Then, using a series of return(1) and return(0), the main application can tell weather everything was sucessful or not.
I have to got to work now (On a sunday!) but I'll chat later this evening about this.
Please let me …
jonnytabpni 0 Light Poster
I think what Jonny wants to do is have two dlls with the same name. Some customers get the one version , and other customers get the other one.
Many programmers have a debug version of a class library, and the production version, and this is exactly what we do is to replace the production DLL on the target machine with the Debug version. Same file name is referenced in the project.
The property settings for the referenced class library is important to make this work.
Another approach, however more complicated is to dynamically load the DLL that you want to use, and deliver both. This is commonly referred to as Plugins or in VS lingo, Add-ons.
I write most of my large projects using the plugin approach because some customers need some extra feature, or want some feature totally different, so we just setup the main application configuration so they can pick the File they want to use from a menu or button, or preload the filename to use in a configuration file, and just load it for them. Another advantage, is that many programmers can work on the project at the same time without bumping into each other, and you can upgrade a customer site with just the changed libraries instead of monolythic exe.
There are many examples of building plugins for C# on the net, but if someone is truely interested in this approach, I can point them to the websites I used, and/or give them a …
jonnytabpni 0 Light Poster
Hi folks,
I've created an application in VS2008 Express Edition. Some of my customers could potentially want slightly different features so I had the idea of moving the relavent stuff to a seperate dll (which works).
The problem is when I swap the dll with a different one I get the error:
"The located assembly's manifest defination does not match the assembly reference"
I'm guessing it's looking for a different version number of the dll.
Any ideas on how to over come this?
If this is just impossible with .NET, can anyone give me some other tips of maybe going about this an alternative way? Like maybe instead of call methods inside a dll, call a seperate application and get the 2 to talk to each other?
Cheers
jonnytabpni 0 Light Poster
Hi Folks,
I have a textbox which looks out for keypresses when it is in focus.
For example, when the ";" key is pressed, a few functions are called. THe problem is, is that in the KeyPress function for the textbox, i have textbox1.Text = ""; to clear it however it doesn't work.
It's as if the text box executes the KeyPress function (hence my clear statement) prior to actually outputting the ";" in the box.
So in the end, ";" gets displayed (However if I keep pressing ";", I only ever see one)
Any ideas on how I can fix this? Thanks
jonnytabpni 0 Light Poster
Hi folks,
I'm sorry if this is the wrong section. I am making an application in VS2008 C# which accesses a 112MB .dbf file using OLEDB which has been taken from an old system.
Please see here for background info:
http://www.daniweb.com/forums/showthread.php?p=860812
Depending on what system I use, seek times vary from 2 seconds to 4 seconds which is not acceptable for the purposes of this program.
I have a corresponding index file (.cdx) however I don't know how to "use it" in my connection string. I have a funny feeling that this is the reason for slow seek times.
Your help is appreciated cheers.
jonnytabpni 0 Light Poster
Thanks for your fantastic help. Hopefully i'll get this solved soon :)
jonnytabpni 0 Light Poster
Also, slightly dissapointing news is that when I moved this software to a less powerful machine (As typical as it will be used), times are way up again :(
jonnytabpni 0 Light Poster
Cheers!
How do I make the database indexed? Actually, I do have an "index file" for this database (Im moving all this stuff from an old system). How do I make use of it in my program? Thanks
jonnytabpni 0 Light Poster
Thanks for your help! Using your logic, I managed to make my ole connection always open!
There does seem to be an improvement. Time is down to about 1.5 - 2.0 seconds! We're making progress.
Any other tips on how to speed up access?
Cheers
jonnytabpni 0 Light Poster
Oh, i forgot to mention. You asked for the rest of my Return class. You have a very good point. The database seems to be VERY responsive when no match is found (indicating that search is fast..)
if (dt.Rows.Count > 0) return (dt.Rows[0]["DESC"].ToString());
else return ("");
The rest of my code knows how to handle an empty return (Displays a message). Cheers
jonnytabpni 0 Light Poster
Thanks for your help.
As a side (but highly relavant note), I change my orignal code from odbc to ole(which uses the microsoft visual foxpro driver) and there is a huge improvement. Times for each query are down from 7 seconds to about 3 seconds. Still too long but an improvement non the less.
I'm gonna try your way with my ole driver to make it static
Thanks
jonnytabpni 0 Light Poster
Hi folks,
I am currently making a piece of software in c# which uses a very large .dbf (yuk!) database (about 120MB). I have a "Remote" class which is used to do the database operations. I use ODBC to connect to this database. All works, except that due to the size of the database, it takes very long for each lookup. For the use of this software, waiting up to 10 seconds for each item to display is not acceptable.
I'm kinda hoping that the problem lies in the fact that the database has to always be opened and closed so I would like to try and see if I could open the database at program startup and then just run the command.
The problem is, no matter what I try, I always get the error Error "The name 'oCmd' does not exist in the current context" and "The name 'oConn' does not exist in the current context".
This is the remote class which works:
public static class Remote
{
public static string GetData(string data,int c)
{
System.Data.Odbc.OdbcConnection oConn = new System.Data.Odbc.OdbcConnection();
oConn.ConnectionString = @"Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=c:\database\;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
oConn.Open();
System.Data.Odbc.OdbcCommand oCmd = oConn.CreateCommand();
oCmd.CommandText = @"SELECT * FROM c:\database\database.dbf WHERE CODE LIKE '" + data + "'";
DataTable dt = new DataTable();
dt.Load(oCmd.ExecuteReader());
oConn.Close();
//bla-bla--bla--following statements just extract the data from the datatable.
}
This is the remote class which doesn't work:
public static class Remote
{
public static void openDatabase()
{
System.Data.Odbc.OdbcConnection …