Click here to Skip to main content

C#

   
Home > Forums > C#

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page  Show 
  Refresh
GeneralRe: Detect Marked Checkbox using OCR Pinmemberenhzflep20:43 22 Feb '12  
Questionsmtp unknown sender PinmemberCS3423:23 21 Feb '12  
AnswerRe: smtp unknown sender PinmvpRichard MacCutchan3:14 22 Feb '12  
Questionadd application to \\root\SecurityCenter2\antispywareproduct as antispyware Pinmemberabhinish23:12 21 Feb '12  
Questionhow can i scann image from scanner in C# PinmemberA7mad_22:55 21 Feb '12  
AnswerRe: how can i scann image from scanner in C# Pinmemberlukeer2:17 22 Feb '12  
Questiontrouble in connecting from C# to Postgre SQL. Pinmemberhellono120:46 21 Feb '12  
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
        {
            //closeConnectDB();
        }
    }
    public static void closeConnectDB()
    {
        //conn.Dispose();
            conn.Close();
        //conn.Dispose();
    }
    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);
            // closeConnectDB();
            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.
AnswerRe: trouble in connecting from C# to Postgre SQL. PinmemberBobJanova21:42 21 Feb '12  
QuestionIntegration of .NET with retail billing machine Pinmembertahernd19:14 21 Feb '12  
AnswerRe: Integration of .NET with retail billing machine PinmvpRichard MacCutchan21:24 21 Feb '12  
AnswerRe: Integration of .NET with retail billing machine PinmemberMycroft Holmes21:39 21 Feb '12  
GeneralRe: Integration of .NET with retail billing machine Pinmembertahernd0:26 22 Feb '12  
QuestionAny difference between Console App and Windows Service for HttpWebRequest..? [Solved] PinmemberTimothy CIAN6:38 21 Feb '12  
AnswerRe: Any difference between Console App and Windows Service for HttpWebRequest..? Pinmemberjschell9:41 21 Feb '12  
GeneralRe: Any difference between Console App and Windows Service for HttpWebRequest..? PinmemberTimothy CIAN10:10 21 Feb '12  
AnswerRe: Any difference between Console App and Windows Service for HttpWebRequest..? PinmvpDave Kreskowiak15:08 21 Feb '12  
GeneralRe: Any difference between Console App and Windows Service for HttpWebRequest..? PinmemberTimothy CIAN3:34 22 Feb '12  
AnswerRe: Any difference between Console App and Windows Service for HttpWebRequest..? [Eureka!] PinmemberTimothy CIAN10:40 22 Feb '12  
GeneralRe: Any difference between Console App and Windows Service for HttpWebRequest..? [Eureka!] Pinmemberjschell11:35 22 Feb '12  
QuestionVisual Studio - Could not load file or assembly 'Microsoft MSXML' PinmemberMember 79805836:27 21 Feb '12  
AnswerRe: Visual Studio - Could not load file or assembly 'Microsoft MSXML' PinmemberEddy Vluggen10:15 21 Feb '12  
GeneralNo help there PinmemberMember 798058310:40 21 Feb '12  
GeneralRe: No help there PinmemberEddy Vluggen10:59 21 Feb '12  
AnswerWell, I solved it. Just install VS 2010 Express PinmemberMember 798058315:42 21 Feb '12  
QuestionClearing ZedGraph curves PinmemberDerecL6:23 21 Feb '12  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Beta | 2.5.120517.1 | Last Updated 22 May 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid