Hola a todos:
Estoy aprendiendo la funcionalidad del Instalador de Visual Studio 2010 y yo nunca pense que me podría encontrar tantos problemas. Yo soy un principiante y esto no es fácil para mí.
Adjunto 2 proyectos del mismo instalador.
A) Problema con el proyecto Instalado1-CS:
El proyector Instalador1-CS tiene los archivos de texto, para la creación de la base de datos, dentro del directorio \DBCustonAction. Este projecto SI produce la base de datos Kardex.mdf correctamente aunque al final recibo los errores siguientes:
1) In GetSQL: El valor no puede ser nulo.
2) Error 1001. El valor no puede ser nulo.
Esto 2 errores aparecen al finalizar de la creación de la base de datos y el proceso se interrumpe después de crear la base de datos correctamente.
B) Problema con el proyecto Instalador2-CS:
El proyector Instalador2-CS tiene los archivos de texto, para la creación de la base de datos, dentro del directorio \DBCustonAction\Scripts. Este projecto NO produce la base de datos Kardex.mdf y al final recibo los errores siguientes:
1) In GetSQL: El valor no puede ser nulo.
2) Error 1001. El valor no puede ser nulo.
Exactamente lo mismo que en el proyecto anterior.
Esto 2 errores aparecen al finalizar la creación de la base de datos y el proceso se interrumpe, después de crear la base de datos.
Parece ser que el Instalador de Visual Studio 2010 no admite que los archivos de texto estén situados en: \DBCustonAction\Scripts, pero ¿por qué?
Yo espero que algún experto revise ambos proyectos y me pueda ayudar a comprender lo que ocurre.
Gracias por adelantado.
ipadilla
Translated into English:
Hi All:
I'm learning the functionality of Visual Studio 2010 Installer and I never thought that I could find so many problems. I am a beginner and this is not easy for me.
I attached 2 projects from the same installer.
A) Problem with Instalado1-CS project:
The projector Instalador1-CS has the text files, to create the database within the \ DBCustonAction. This project produces the Kardex.mdf database correctly but in the end I get the following errors:
1) In name: GetSQL: Value can not be null.
2) Error 1001. The value can not be null.
This 2 errors appear when you finish creating the database and the process stops after creating the database.
B) Problem with the project Instalador2-CS:
The projector Instalador2-CS has the text files, to create the database within the \ DBCustonAction \ Scripts. This project does not produce the database Kardex.mdf and finally I get the following errors:
1) In name: GetSQL: Value can not be null.
2) Error 1001. The value can not be null.
Exactly the same that in project Instalador1-CS.
This 2 errors appear when you finish creating the database and the process stops after creating the database.
It seems that the Visual Studio 2010 does not support text files which are located at: \ DBCustonAction \ Scripts, but why?
I hope some expert review both projects and can help me understand what is happening.
Thanks in advance.
ipadilla
Loading
Guest UserPosted Aug 12, 2011, 1:50 PM
La búsqueda distingue entre mayúsculas y minúsculas, y el nombre del archivo no coincide con la cadena (nótese la "S" al final).
Además, hay errores en los siguientes guiones. Pruebe a ejecutar directamente en el Administrador de SQL y lo entenderás:
aspnet_UnRegisterSchemaVersion.txt
PA_registrarEmpleado.txt
------------------------------------------------------------------------------
In Instalador1-CS, the problem is this line:
Also, you have errors in the following scripts. Try running them directly in SQL Manager and you'll understand:
aspnet_UnRegisterSchemaVersion.txt
PA_registrarEmpleado.txt
Isidro PadillaPosted Aug 15, 2011, 8:09 AM
Propiedades->Aplicacion-> Espacio de nombre raíz debe completarlo con: DBCustomAction.Scripts.
Saludos
Translated into English:
Hello John, the problem of the path in VB.Net for embedded files is resolved as follows:
Properties-> Application-> Root namespace should be completed with: DBCustomAction.Scripts.
Regards.
Isidro PadillaPosted Aug 14, 2011, 9:49 AM
Cuando un día se me ocurrió aplicarlo, después de observar un ejemplo en VB.Net, me encontré con la sorpresa de que me aparecían una serie de errores que no sabía interpretar. Además hay alguna diferencia entre VB.Net y Csharp que me rompía los esquemas, fue tedioso...
Al final, después de romperme la cabeza, téngase en cuenta que no soy un profesional de la informática, recurrí a los foros de csharp (concretamente a "Foro C# Corner" y " Foro en Lenguaje C#"), sección ADO NET & Database. Allí encontré la ayuda que necesitaba.
Buenos "amigos" internautas como John Penn o Pedro Hurtado me ayudaron a confeccionar estos ejemplos en VB.Net y Csharp que creo tienen un gran valor para las personas que se quieran introducir en la creación de bases de datos por este sistema.
Como pienso que este trabajo puede ser de gran utilidad para mucha gente que se inicia, aquí los tenéis.
https://skydrive.live.com/?cid=d524aa1b7050d43a&sc=documents&uc=1&id=D524AA1B7050D43A%21111#
Algunos consejos para novicios.
1)El trabajo con sentencias SQL es tedioso y una fuente de errores difíciles de detectar cuando no eres un profesional experimentado. Sería una buena práctica probar dichas sentencias en el SQL Server Management antes de incluirlas en la programación del Instalador de la base de datos. Yo tenía varios errores en los procedimientos almacenados.
2)En teoría el tratamiento de las rutas establecidas para los archivos de texto que se usarán para crear la base de datos debería ser el mismo, pero esto no es así, especialmente en lo que se refiere a la ruta de tales archivos. Cuando los archivos está en la carpeta raíz no hay problema, pero si que lo hay cuando se colocan en una subcarpeta. En tal caso la ruta se debe establecer como sigue:
this.ExecuteSql("Kardex", this.GetSql("Carpeta.sql.txt"))
Esto es válido para la programación csharp, pero no funciona en VB.Net, en cuyo caso hay que escribirlo como si estuvieran colocados en la carpeta raíz, así:
this.ExecuteSql("Kardex", this.GetSql("sql.txt"))
¿Por qué? No lo sé. Aunque no he tenido tiempo de averiguarlo pero podría ser que VB establece la ruta cuando se establece el archivo de texto como "recurso incrustado".
Obsérvese que la ruta en los archivos de recursos incrustados se establece cambiando la doble barra o simple barra invertida ( "\\" o "\") por un punto "."
3)Es fundamental establecer controles que nos indiquen donde se produce el error, los ejemplos adjuntos llevan incorporadas las mejoras propuestas por John Penn y Perdro Hurtado.
4)No te guardes para ti lo que aprendas, publícalo para facilitarle la labor a los demás. Lo que no se le ensaña a los demás se pierde para siempre. El trabajo en equipo es mucho más productivo y enriquece a la sociedad.
Amen!
Gracias a John Penn y a Pedro Hurtado por resolver mis dudas con elegancia, precisión, rapidez y generosidad.
Hasta siempre amigos.
Translated into English:
When one day it occurred to me to apply it, after seeing an example in VB.Net, I found myself surprised to find a number of mistakes I could not interpret. There is also a difference between VB.Net and Csharp I could not understand, was tedious ...
Finally, after breaking my head, please note that I am not a computer professional, I turned to forums csharp (specifically "Forum C # Corner" and "Forum C # language "), ADO NET & Database section. There I found the help I needed.
Internet good friends like John Howard or Peter Penn helped me make these samples in VB.Net. Csharp and I think they have great value for people who want to enter in the creation of databases by this system.
As I think this work can be very useful for many people who start this kind of programming, here you have the examples.
https://skydrive.live.com/?cid=d524aa1b7050d43a&sc=documents&uc=1&id=D524AA1B7050D43A%21111#
Some tips for novices.
1) Working with SQL statements is tedious and a source of error difficult to detect when you're not an experienced professional. It would be good practice to test these statements in the SQL Server Management before being included in the programming of the Installer database. I had several errors in stored procedures.
2) In theory the treatment of established routes for text files that are used to create the database should be the same for both VB and C #, but this is not true, especially in regard to the route of such files. When these files are in the root folder no problem, but appear when placed in a subfolder. In this case the route should be set as follows:
this.ExecuteSql ("Kardex" this.GetSql ("Carpeta.sql.txt"))
This is true for programming csharp, but does not work in VB.Net, in which case we write it as if they were placed in the root folder, thus:
this.ExecuteSql ("Kardex" this.GetSql ("sql.txt"))
Why? I do not know. Although I have not had time to check this out now could be that VB sets the path when you set the text file as "embedded resource" •
Note that the path in the embedded resource files is set by changing the single or double backslash ("\" or "\ \") for a period "."
3) It is essential to establish controls that indicate where the error occurs, the accompanying examples have built the improvements proposed by John Penn and Pedro Hurtado.
4) Do not keep it to yourself what you learn, publish it to facilitate the work of others. What we not be able to convey to our fellow man is lost forever. Teamwork is more productive and enriching to society.
Amen.
Thanks to John Penn and Pedro Hurtado to resolve my doubts with elegance, precision, speed and generosity.
Farewell friends.
Isidro PadillaPosted Aug 14, 2011, 3:21 AM
I'm cleaning up the source files of each of the projects to attach them all together in this thread to help other people.
Thank you very much for your help and hope to find you again in the forum.
ipadillar
Guest UserPosted Aug 13, 2011, 10:58 PM
---------------------------------------------------------
For some reason I don't yet understand, you don't need to specify the "Scripts." prefixes on the filenames in the VB version. After I removed all of them, the installer worked as expected.
Isidro PadillaPosted Aug 12, 2011, 5:18 PM
Esta tarde he estado preparando la solución para colocar el mensaje aquí en el foro y hacer pública la solución. Ha sido una grata sorpresa encontrarte de nuevo.
John resulta que estoy aprendiendo a programar con visual Studio, pero como puedes comprobar me falta mucho todavía para dejar de ser un aprendiz. He encontrado una cierta dificultad con los archivos incrustados y me he propuesto a aumentar mis conocimientos con la ayuda de personas generosas como tú.
En este momento ya he logrado que el proyecto funcione en los casos siguientes:
a) Cuando los archivos de recursos están situados en el directorio raíz y la programación en Csharp.
b) Cuando los archivos de recursos están situados en un subdirectorio y la programación en Csharp.
c) Cuando los archivos están en el directorio raíz y la programación en se realiza VB.Net.
Pero no he logrado todavía que funcione el siguiente:
d) Cuando los archivos están en un subdirectorio y la programación se realiza en VB.Net.
Este último proyecto d) no logro que me genere la base de datos Kardex a pesar de que ya he corregido todos los errores. No me reconoce la ruta después de cambiar "\\" por "."
Bueno John, estoy seguro que tu vas a descubrir la causa…
Para todos aquellos que estén interesados adjunto un archivo .rar con todo lo realizado hasta ahora, incluido "TestInstaller" para localizar errores, similar al que tú me has proporcionado en este hilo.
El proyecto que aun no funciona de llama "Instalador-VB-Pendiente " y está en el directorio \BDKardex-Net Reflector-Recursos en Directorio Scripts.
Saludos y gracias de nuevo.
Translated into English:
John, thank you very much for your help. The same answer you give me, yesterday gave me another great friend, Pedro Hurtado, whereupon the problem is solved and the answer you provide to me is exactly the same, including errors in SQL statements that you show me.
This afternoon I have been preparing the solution to put the message here in the forum and make public the solution. It was a pleasant surprise to find you again.
John, is that I'm learning to program with Visual Studio, but as you can see me still a long way to stop being an apprentice. I found some difficulty with embedded files and I plan to increase my knowledge with the help of generous people like you.
At this point I have made the project work in the following cases:
a) When the resource files are located in the root directory and Csharp programming.
b) When the resource files are located in a subdirectory and programming in Csharp.
c) When the files are in the root directory and programming is done in VB.Net.
But I have not yet managed to work the following:
d) When the files are in a subdirectory and programming is done in VB.Net.
The latter project d) I can not get that generates the database Kardex, even though I have corrected all errors. This does not recognize the path after changing "\ \" with "."
Well John, I'm sure you're going to discover the cause ...
For those interested I attach a .rar file with everything done so far, including a project "TestInstaller" for detecting errors, similar to what you have provided me in this thread.
The project still does not work called "Installer-VB-Pending" and is located in \ BDKardex-Net Reflector-Resources Directory Scripts.
Greetings and thanks again.
ipadilla
Guest UserPosted Aug 12, 2011, 2:11 PM
La diferencia entre los dos proyectos es que en el # 1 de la acción personalizada está en la misma carpeta que los guiones, y en el # 2 las secuencias de comandos en una subcarpeta.
------------------------------------------------------------------------
For Instalador2-CS, you need to change the references to the scripts to use dot notation, as in:
The difference between the two projects is that in #1 the custom action is in the same folder as the scripts, and in #2 the scripts are in a subfolder.
Guest UserPosted Aug 12, 2011, 1:52 PM
I modified 2 of the custom action's methods as follows so that I could diagnose the problem:
private string GetSql(string Name)
{
string asmName = String.Empty;
try
{
// Gets the current assembly.
Assembly Asm = Assembly.GetExecutingAssembly();
// Resources are named using a fully qualified name.
asmName = Asm.GetName().Name + "." + Name;
Stream strm = Asm.GetManifestResourceStream(asmName);
// Reads the contents of the embedded file.
StreamReader reader = new StreamReader(strm);
return reader.ReadToEnd();
}
catch (Exception ex)
{
MessageBox.Show("In GetSQL: " + ex.Message + @", can't find stream for " + asmName);
throw (ex);
}
}
private void ExecuteSql(string DatabaseName, string Sql)
{
System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand(Sql, masterConnection);
// Initialize the connection, open it, and set it to the "master" database
masterConnection.ConnectionString = (string) My.Settings.Default.masterConnectionString;
Command.Connection.Open();
Command.Connection.ChangeDatabase(DatabaseName);
try
{
Command.ExecuteNonQuery();
}
catch(Exception e)
{
MessageBox.Show("Error occurred in ExecuteSql..." + e.Message + Environment.NewLine + "Sql=" + Sql);
}
finally
{
// Closing the connection should be done in a Finally block
Command.Connection.Close();
}
}