Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have written the following code to implement common connection string so that all the forms use the connection string provided in Login Form of my application.The application works fine on my machine but when I run my application on any other machine I get the error "Connection to the server could not be established" ie it enters the catch block. even when the UDL file is available on the machine.Can anyone help me to rectify this. Thanks


C#
public void FrmLogin_Load(object sender, EventArgs e)
        {


            btncancel.CausesValidation = false;


            try
            {

                string FileName = "Intellect_LeadMt.udl";
                if (!File.Exists(FileName))
                {
                    MessageBox.Show(FileName + " File is not available in current folder!");
                    //return;
                    this.Close();
                }

                string[] str = File.ReadAllLines(FileName);
                con = new OleDbConnection(str[2]);
                con.Open();

                add = new AddModify_Lead(this);
                foll = new Follow_Lead(this);
                rem = new Reminder_Lead(this);
                ContctAdd = new AddContact(this);
                UtilityMaster = new UtilityMasters(this);
                LeadManagerForm = new LeadManager(this);
                Register = new FrmRegistration(this);
                Mainform = new Form1(this);
                Ld = new LoginDetails(this);
                Ul = new UserLog(this);
                Mc = new Modify_Client(this);
            }
            catch
            {
                MessageBox.Show("Connection to Database currently is unavailable!\n Please Check udl and start application once again.\n Sorry For the inconvenience", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Application.Exit();

            }

          }
Posted
Updated 2-Dec-14 21:58pm

1 solution

You are swallowing exception in your method. if you need to find error details you may need to show full error as message or write the full error to a textile. for example:
C#
try
{
  // your code 

}catch(Exception ex)
{
  //1. show full error message 
  //MessageBox.Show(ex.ToString());
  //or
  //2. show StackTrace
  //MessageBox.Show(Ex.StackTrace);
  //or
  // log the errors to a file..
}          

then you able to find the detailed error and it will help you to find solution.
 
Share this answer
 
Comments
vivek murli 3-Dec-14 3:07am    
Thanks DamithSL will give it a try

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900