system.nullreferenceexception:object reference not set to an instance at program.main
i am using C# desktop application and ms sql server database.
i can run my project in the local pc when i run it from my project or from the .exe file in the debug folder. it runs fine.
but when i copy the .exe file from debug or release folder and put it in other folder even in the same pc.. it show me error
Code:
system.nullreferenceexception:object reference not set to an instance of an object.
at Form1..ctor()
at program.main()
where form1 is the main form of my application.
please help me
Code:
public partial class Form1 : Form
{
SqlConnection dbcon = new SqlConnection(ConfigurationManager.ConnectionStrings["rentaldbcon"].ConnectionString);
public Form1()
{
InitializeComponent();
}
Code:
static class Program
{
/// Program.cs
[STAThread]
static void Main()
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
help me please
Re: system.nullreferenceexception:object reference not set to an instance at program.
Are you copying the config file with the EXE? That connection string your loading is stored in the config file so, if there's not config file, there's no connection string.