Dear, I have a problem, I have a project in vs2008 that works perfectly, I create the installer and everything is fine, the inconvenience is to install it in another machine it does not work, I put a log to see where the error comes from, and in Every time the program tries to access the app.config the exception "reference to object not established as instance ..." jumps, and that happens every time I try to access the key of the app.config. When installing in the directory where the application is installed if the app.config appears and an app.dll.config, but as I say does not recognize it does not access or do not know what is the dilemma after installing it that can not access the app.config.
This is the method where the error occurs:
public OleDbConnection CConec()
{
FileStream stream = new FileStream("c:\xxx\" + DateTime.Now.Hour.ToString() + "_" + DateTime.Now.Minute.ToString() + "_" + DateTime.Now.Second.ToString() + ".txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine("First Line");
// Escribimos fecha y hora del instante
writer.WriteLine("Second Line and time " + DateTime.Now);
// Escribimos User y Hostname del equipo
System.Security.Principal.WindowsIdentity user = System.Security.Principal.WindowsIdentity.GetCurrent();
writer.WriteLine("User : " + user.Name);
writer.WriteLine("Hostname : " + Environment.MachineName);
try
{
writer.WriteLine("000");
p_strSVRSQL = ConfigurationSettings.AppSettings["SVRSQL"].ToString();
writer.WriteLine("111");
p_strUSRSQL = ConfigurationSettings.AppSettings["USERSQL"].ToString();
writer.WriteLine("222");
p_strPWDSQL = ConfigurationSettings.AppSettings["PWDSQL"].ToString();
writer.WriteLine("333");
//strCnn = "Provider=SQLOLEDB.1;Server=" + p_strSVRSQL + ";Database=MICDB;Uid=" + p_strUSRSQL + "; Pwd=" + p_strPWDSQL + ";";
//strCnn = "Provider=SQLOLEDB.1;Server=" + Environment.MachineName + @";Database=MICDB;Uid=" + p_strUSRSQL + "; Pwd=" + p_strPWDSQL + ";";
strCnn = "Provider=SQLOLEDB.1;Server=" + Environment.MachineName + @"\SQLEXPRESS;Database=xxx;Uid=xxx" + "" + "; Pwd=xxx" + "" + ";";
//strCnn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MICDB;Data Source=" + p_strSVRSQL;
writer.WriteLine("444");
oCon = new OleDbConnection(strCnn);
writer.WriteLine("555");
oCon.Open();
writer.WriteLine("666");
p_strStateConex = "Conectado A " + p_strSVRSQL;
writer.WriteLine(p_strStateConex + " con " + strCnn);
writer.Close();
}
catch (Exception ex)
{
writer.WriteLine(ex.Message);
writer.Close();
}
return oCon;
}
As you can see there is code (which increases to see the error) to keep line by line what happens, and the content of the file is:
First Line Second Line and time 5/19/2016 6:35:50 PM User: xxx-90B2E1 \ Administrator Hostname: xxx-90B2E1 000 Object reference not set as an instance of an object
And as I said before, in development works perfectly, once installed on a client machine is the problem.
Note. 1. All the code to write in a text file will increase it to see where and what happens in the client, that is to see until what line is executed and what is the exception. 2. The machine where I develop is WXP with VS2008, the machine where I install in a W7.
Greetings.