应用程序启动时未找到UDL文件异常 [英] UDL File not found exception on Application Start

查看:342
本文介绍了应用程序启动时未找到UDL文件异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下代码来实现公共连接字符串,以便所有表单都使用我的应用程序的登录表单中提供的连接字符串。应用程序在我的机器上工作正常,但是当我在任何其他机器上运行我的应用程序时,我得到错误无法建立与服务器的连接,即它进入catch块。即使UDL文件在机器上可用。任何人都可以帮我纠正这个问题。谢谢





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


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();

            }

          }

推荐答案

您正在吞噬方法中的异常。如果您需要查找错误详细信息,则可能需要将完整错误显示为消息或将完整错误写入纺织品。例如:

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:
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.


这篇关于应用程序启动时未找到UDL文件异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆