无法运行从C#创建的.exe文件 [英] Not able to run the .exe file created from c#

查看:520
本文介绍了无法运行从C#创建的.exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Visual Studio 2010中使用C#创建了一个Windows窗体应用程序,该应用程序连接了SQL Server中的数据库.完成所有开发工作后,我将在计算机中生成的exe文件复制并粘贴到另一台计算机中,然后尝试执行该文件,但该文件无法正常工作.

I have created a Windows form application using C# in visual studio 2010 connecting the database in SQL server . After all my development is done i copy the exe file generated in my machine and pasted in another machine and try to execute it but it is not working .

我可以看到该进程已在任务管理器中启动,但5秒后已关闭.我什至尝试为该应用程序创建安装程序,并将其安装在该机器上,但仍然面临相同的问题.

i can see the process started in task manager but it was closed after 5 seconds . I even tried creating the setup for this application and installed in that machine still i am facing the same issue .

但是在我的机器上,这两种方式都可以正常工作.谁能帮助我找到我哪里出了问题.

But in my machine it is working perfectly in the both the ways . can any one help me in finding where i went wrong .

预先感谢

推荐答案

由于您没有提供错误信息,因此您得到的答案和评论都是有根据的猜测.

As you don't provide the error, the answers and comments you are getting are educated guesses.

您应检查事件查看器中的错误...

这将使您了解正在发生的事情.如果您无法解决,请将此信息添加到您的问题.

This will let you learn what is going on. If you can't fix it, add this info to your question.

由于您没有发布异常消息,可能您没有正确地捕获异常.只是要确保将您的主要功能包含在尝试/捕获"中.

As you are not posting exception message, probably you re not properly catching exceptions. Just to be sure surround your main function in a Try/Catch.

在Catch中,编写一些代码以将消息异常转储到文件中,甚至更好地使用Log4Net.为简单起见,只需添加一些代码即可立即写入文件.像这样:

In Catch, write some code to dump message exception into a file, or even better use Log4Net. For simplicity just add some code to write to a file now. Something like:

    static void Main()
    {
        try
        {
            //Your code
        }
        catch (Exception ex)
        {
            //Write ex.Message to a file
            using (StreamWriter outfile = new StreamWriter(@".\error.txt"))
            {
                 outfile.Write(ex.Message.ToString());
            }
        }
    }

PS:如果它是一个控制台应用程序,则可以使用Console.Write

PS: If it is a console application you can survive with Console.Write

这篇关于无法运行从C#创建的.exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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