|
Hi all.
I'm now developing a website that connect to Postgre SQL database. I used NpgSQL.DLL to connect from C# to database. I also finished testing this project in my local pc, it worked well. But unfortunately it did not work well in server. Some errors in connecting to server happened.
These errors happened when website had much people logged in and began using database query functions ( select, update, delete .. ). I think errors begin from codes in connect database functions. but i still can not fix it. this is my connecting database codes.
------ codes connects database ---------
-- Connect.cs file.
public static void connectDB()
{
try
{
conn.ConnectionString = connection;
conn.Open();
}
catch
{
}
}
public static void closeConnectDB()
{
conn.Close();
}
public static int ExecuteQuery(string SQL)
{
try
{
connectDB();
NpgsqlCommand cmd = new NpgsqlCommand(SQL, conn);
return cmd.ExecuteNonQuery();
}
catch
{
closeConnectDB();
return 0;
}
}
public static DataSet SelectQuery(string SQL)
{
DataSet ds = new DataSet();
try
{
connectDB();
NpgsqlDataAdapter nDa = new NpgsqlDataAdapter(SQL, conn);
nDa.Fill(ds);
return ds;
}
catch
{
closeConnectDB();
return ds;
}
}
----------------- use to execute these codes --------
....
--- calling functions files.
try
{
string strTest = "Select * from abc where .. ";
DataSet ds1 = new DataSet();
ds1 = Connect.SelectQuery(strTest);
if (ds1.Tables[0].Rows.Count > 0)
{
}
else
{
int kq = Connect.ExecuteQuery(strInsert);
if (kq > 0)
{
int kk = Connect.ExecuteQuery(strUpdate);
kk = Connect.ExecuteQuery(strUpdate2);
strHTML = "OK";
}
}
}
catch
{
strHTML = "errors.";
}
finally
{
int kk = Connect.ExecuteQuery(strUpdate);
kk = Connect.ExecuteQuery(strUpdate2);
strHTML += "-- Sub Finally";
}
-----------------End calling function---------------
Here sometimes it worked well but sometimes catched errors.
Can you help me? thanks and regards.
|
|
|
|
|
Don't just swallow exceptions, at the very least you should log them to console or a log file so you can look at the stack trace and exception message. Those error messages will almost certainly give you a big clue as to the problem.
|
|
|
|
|
Hi everyone,
I want to integrate a C# application for paperless billing with a retail billing machine (those which are used in shopping malls for generating bills). Is there any way it can be done? Did not get any information about it on Google.
-Please help.
|
|
|
|
|
tahernd wrote: I want to integrate a C# application for paperless billing with a retail billing machine
What software exists in this machine and what interface(s) does it provide (both software and hardware) for connection with other applications?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
tahernd wrote: retail billing machine
Probably because you need to give it another name, cash register, and they run Point Of Sale (POS) software.
As Richard said find out the the POS being used and see if it has an API/Interface you can hook into.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks
Got some reference C# API for POS.
|
|
|
|
|
I am using an HTTP-based API to a 3rd-party service. Its usage involves two steps: POSTing a login command (which saves the session in a cookie), then issuing another command. I have tested this successfully in a console app, but when I try to use it in a (production) Windows service I am getting a 407 Proxy error back.
Is there some difference between them regarding HttpWebRequests? I don't believe so but I'm scratching my head here.
private WebResponse webPOST(string URLextension, string Parameters)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(BASE_URL + URLextension);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Headers.Add("X-Requested-With: C# Interface");
request.CookieContainer = _cookieJar;
request.Timeout = 3600000;
if (_proxy != string.Empty)
{
request.Proxy = new System.Net.WebProxy(_proxy, false);
request.Proxy.Credentials = new
NetworkCredential(_proxyUser.ConvertToUnsecureString(), _proxyPass.ConvertToUnsecureString());
}
byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes(Parameters);
Stream reqstr = request.GetRequestStream();
reqstr.Write(buffer, 0, buffer.Length);
reqstr.Close();
return request.GetResponse();
}
The _cookieJar is a private property used to store the cookie generated by login. Both the login command and the "objective" command are issued via this private method, and the entire thing works with no errors in a console app.
|
|
|
|
|
The windows service is running under a user. Did you test the console app while logged in as that user?
|
|
|
|
|
A good idea, and I tried running the console app under the same account as the service and it worked, so no change there. It always seems to run as a console app but never under the Windows service.
I had previously done the reverse (run the service under the same credentials as I was using for the console app), but it did not work.
Thanks...
|
|
|
|
|
The window service is running, by default, under the Local System account, which probably does not have access to your proxy server. The 407 error is Authentication Required, which is why your code works when running from a Console app, which is run by you and runs AS you and it doesn't work as a service.
|
|
|
|
|
I understand what you are saying, but that is not the case here. The sevice is running under the same credentials used for proxy authentication; I changed it after I first installed the service by running services.msc and changing it on the "Log On" tab on the service's properties. I have run the console app under that account though, and it worked (unlike the service).
What you're saying is valid, but it was already covered...
But I'm still scratching my head on this.
|
|
|
|
|
I have solved the mystery...
The problem was not in the code above, but in what was done with the response stream, which is in XML. Unfortunately, that XML contains a DTD that was causing the problem, when the XmlDocument class tried to retrieve it and failed (because it's not using the proxy credentials properly).
And, of course, the "difference" was that in my console app I was just spitting the XML onto the screen, not loading an XmlDocument class.
Thanks for the help for those who looked, though...
|
|
|
|
|
Timothy CIAN wrote: And, of course, the "difference" was that in my console app I was just spitting
the XML onto the screen, not loading an XmlDocument class.
Ahh...
When I deliver a windows service I deliver it with a corresponding console app.
The service code and the console code do nothing except call to the real functionality of the system.
|
|
|
|
|
Hopefully no one minds if I put this here and hopefully someone knows the answer. I'm trying to do it in C#. I put it on Technet, but no replys yet. There does not seem to be any reference to this on the web.
I have a real problem. I have Visual Studio 2010 Professional (on Windows 7 Proefessional). If I try to open a .CS file of a project from the Solution Explorer, I get the message (that can't be copied and pasted). The same thing happens if I try to start a new project.
Could not load file or assembly 'Microsoft MSXML, Version=8.0.0.0, Culture=neutral, PublicKey Token=b03f5f7f11d50a3a' or one of its dependencies. The module was expected to contain an assembly manifest.
I researched this on the web and it's about the MS XML parser (web messages about that are complicated with 4 versions of the dll). c:\windows\assembly\Microsoft.MSXML. I cannot find anything about this error message. I reloaded SP1 for luck... That got me a new message about some editor software not loading correctly, but did not fix the problem.
It used to work right. I made no environment changes that I know of. This is a simple Windows application, but it has the same failure when trying to open a *.aspx.cs file. When trying to open a .ASPX file, the error message is: Visual Studio has encountered an unexpected error. Helpful, that one.
I don't really want to re-install Visual Studio (wherever the disk is right now).
Notice that it says the problem is the assembly manifest.
Anyway, any thoughts would be really appreciated.
Thanks, Mike
|
|
|
|
|
Try this[^] one.
Member 7980583 wrote: I don't really want to re-install Visual Studio (wherever the disk is right now).
One install per license. If the disc is lost, the installation is lost.
Seen one too many software-shop that does "everything" to prevent pirating their product while using illegal version of Windows/Visual Studio/Sql Server..
Bastard Programmer from Hell
|
|
|
|
|
I think I tried that, but it didn't fix it. I did reboot to make sure.
Can't believe no one has see this before.
|
|
|
|
|
Aw, many have seen this before, and most of the time it's fixed with updating the MS XML libraries. If doesn't, chances are that your program requires a specific version.
Bastard Programmer from Hell
|
|
|
|
|
I installed Visual Studio 2010 Express and my Visual Studio 2010 Professional worked.
|
|
|
|
|
Hello, I am making some program where I am using zedgraph libraries. And I have a little problem on clearing curves. When form loads I add graph and I want to clear the curves when I press the button Clear and then press Start start over again. Creating graph there is now problem but when I press Clear and Start again it doesn't start again. I give you some fragments of the code how I clear it.
private void Clear_Click(object sender, EventArgs e)
{
zg1.GraphPane.CurveList.Clear();
zg1.GraphPane.GraphObjList.Clear();
zg1.Invalidate();
}
|
|
|
|
|
I'm not familiar with the control; however, one should be able to remote the entire control and create a new one. Have you tried creating a new ZegGraph ?
Bastard Programmer from Hell
|
|
|
|
|
hot to get processor ID in C#
|
|
|
|
|
|
If you're talking about getting the capabilities of the processor, please continue reading the link posted by the other responder.
If you're talking about getting the processor serial number (CPUID), don't bother. Only Intel and Transmeta ever implemented it for a short time in certain CPU models. Intel doesn't even implement it in the latest CPUs and AMD never implemented it at all. It's utterly useless to identify a machine uniquely.
|
|
|
|
|
Hello
Add the System.Management reference
And use the following code
public static String GetCPUId()
{
String processorID = "";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"Select * FROM WIN32_Processor");
ManagementObjectCollection mObject = searcher.Get();
foreach (ManagementObject obj in mObject)
{
processorID = obj["ProcessorId"].ToString();
}
return processorID;
}
P.S :
Some CPU didn't support the CPUID instruction, in which case, the call can't be guaranteed to succeed.
|
|
|
|
|