Hola a todos.
Estoy creando una base de datos mediante programación C#, según el proyecto adjunto, pero tengo problemas con la base de datos generada porque el método no me acepta los acentos y carácteres especiales como la "ñ",por favor véase la imagen adjunta dentro del zip (image.gif).
My pregunta es la siguiente, ¿alguien me puede ayudar a resolver este problema?
Y una segunda pregunta relacionada con el archivo incrustado "Create_View_Vst11Producto.txt" ¿por qué no es aceptada esta línea?:
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Gracias por adelantado.
ooooooooooooooooOOOOOOOOOOOOOOOOOOOOOOOOOoooooooooooooooooo
Translate into English:
Hi all.
I am creating a database using C # programming, according to the attached draft, but I have problems with the database generated because the method does not accept me the accents and special characters like "ñ", please see the attached image in the zip (image.gif).
My question is this, anyone can help me solve this problem?
And a second question related to the embedded file "Create_View_Vst11Producto.txt" Why is not accepted this line?:
EXEC N'MS_DiagramPane1 sys.sp_addextendedproperty @ name = ', @ value = N' [0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Thanks in advance.
Loading
Isidro PadillaPosted Nov 25, 2011, 4:17 AM
Bueno, veo que lo expliqué tan mal que ustedes no pudieron comprender lo que proponía.
Lo que yo proponía era crear varias consultas mediante un bucle para poder dividir el script cuando éste se haga muy grande.
No he encontrado la forma de hacerlo con un bucle porque yo no conozco como meter en una lista los archivos ".sql" que he incrustado en el programa instalador.
Pero hay una forma sencilla de hacerlo creando más de una consulta. Aquí les pongo un ejemplo duplicando la consulta. Podemos hacer las consultas que queramos, aunque la forma no sea elegante.
De todas formas si alguien conoce una forma más elegante de hacerlo le sugiero que la comparta.
Saludos.
Translate into English:
Well, I see that I explained it so bad that you could not understand what I proposed.
What I proposed was to create multiple queries in a loop to divide the script when it gets too big.
I have not found a way to do it with a loop because I do not know embedded putting ".sql" files in a list and then create the loop.
But there is a simple way creating more of a query. Here I put a duplicate query. We can create all queries we want although is not an elephant way.
Anyway if anyone knows a more elegant way to do this I suggest you share it.
Greetings.
Example with 2 queries:
cadenaConexion.Replace("Database=master", "Database=" + txtBaseDatos.Text);
using (SqlConnection conexion = new SqlConnection(cadenaConexion.ToString()))
{
conexion.Open();
using (SqlTransaction transaccion = conexion.BeginTransaction())
{
using (SqlCommand comando = new SqlCommand("", conexion, transaccion))
{
try
{
string[] consultas = null;
consultas = File.ReadAllText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Script.sql").Split(new string[] { "GO" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string stringQuery in consultas)
{
comando.CommandText = stringQuery;
comando.ExecuteNonQuery();
}
transaccion.Commit();
}
catch (Exception exc)
{
transaccion.Rollback();
MessageBox.Show("Ocurrió un error al tratar de crear la estructura de la Base de Datos.\n" + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (MessageBox.Show("¿Desea cancelar la instalación?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
throw new InstallException("Error al crear la estructura.", exc);
else
return;
}
}
}
}
//========================================== Second query
cadenaConexion.Replace("Database=master", "Database=" + txtBaseDatos.Text);
using (SqlConnection conexion = new SqlConnection(cadenaConexion.ToString()))
{
conexion.Open();
using (SqlTransaction transaccion = conexion.BeginTransaction())
{
using (SqlCommand comando = new SqlCommand("", conexion, transaccion))
{
try
{
string[] consultas_1 = null;
consultas_1 = File.ReadAllText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Script1.sql").Split(new string[] { "GO" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string stringQuery in consultas_1)
{
comando.CommandText = stringQuery;
comando.ExecuteNonQuery();
}
transaccion.Commit();
}
catch (Exception exc)
{
transaccion.Rollback();
MessageBox.Show("Ocurrió un error al tratar de crear la estructura de la Base de Datos.\n" + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (MessageBox.Show("¿Desea cancelar la instalación?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
throw new InstallException("Error al crear la estructura.", exc);
else
return;
}
}
}
}
Isidro PadillaPosted Nov 22, 2011, 9:55 AM
lamento la tardanza pero no he sido capaz de que el instalador acepte los caracteres especiales.
Así que he buscado entre algunas de las cosas que voy guardando y he encontrado uno que funciona. La verdad es que no conozco quien ha sido su credador, pero yo lo he adaptado y éste funciona correctamente.
Lo adjunto para que puede ser de utilidad para aquellos que aun no están familiarizados con las creación de este tipo de projectos.
Tal como esta diseñado el instalador solo permite el uso de un archivo (".sql"). Véase la línea "Consultas = ".
Mi próxima tarea será crear un bucle para poder utilizar distintos fragmentos del script de la base de datos (es decir, varios archivos (.sql), para los casos en que se incluya un número importante de datos. En tal caso el archivo (".sql") podría llegar a ser muy grande.
Como yo voy mal de tiempo si alguien me ayuda a crear el bucle que dejo indicado en el código adjunto, yo se lo agradeceré.
Translate into English:
Hi colleagues,
sorry for the delay but I have not been able to have the installer accept special characters.
So I searched among some of the things I saved and I found one that works. The truth is I do not know who has been his credador, but I've adapted and it works correctly.
I attached so it can be useful for those who are not yet familiar with the creation of such projects.
As the installer is designed only allows the use of a file (. "Sql"). See the line "Consultas =".
My next task will be to create a loop to use fragments of the script of the database (ie, multiple files (. Sql) for cases that include a significant number of data. In this case the file (". sql ") could become very large.
As I go short of time if someone helps me create the loop that indicated on the left attached code, I would be grateful.
oooooooooooooooooooOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOooooooooooooooooooooooooooooooooooo
using (SqlConnection conexion = new SqlConnection(cadenaConexion.ToString()))
{
conexion.Open();
using (SqlTransaction transaccion = conexion.BeginTransaction())
{
using (SqlCommand comando = new SqlCommand("", conexion, transaccion))
{
Loop coul be like this more or less:
Object[] myObjArray = new Object[n] { Script1.sql, Script2.sql, Script3, Script4.sql, ... };
foreach ( Object i in myObjArray )
{
try
{
string[] consultas = null;
consultas = File.ReadAllText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\BaseDatos.sql").Split(new string[] { "GO" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string stringQuery in consultas)
{
comando.CommandText = stringQuery;
comando.ExecuteNonQuery();
}
transaccion.Commit();
}
catch (Exception exc)
{
transaccion.Rollback();
MessageBox.Show("Ocurrió un error al tratar de crear la estructura de la Base de Datos.\n" + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (MessageBox.Show("¿Desea cancelar la instalación?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
throw new InstallException("Error al crear la estructura.", exc);
else
return;
}
}
}
}
}
Isidro PadillaPosted Nov 12, 2011, 9:30 AM
Solicito perdón por el retraso, he estado unos días sin tiempo para poder visitar el foro. Voy a echar un vistazo y aplicar vuestras propuesta. Si consigo solucionarlo os prometo daros respuesta sobre el resultado.
Saludos y Gracias de nuevo.
Translated into Engles:
Thank you all for your help.
I beg you pardon for the delay, I have been a few days without time to visit the forum. I'll take a look and implement your proposal. If I fix it I promise to give you an answer about the results.
Greetings and thanks again.
Sam HobbsPosted Nov 7, 2011, 9:22 PM
There is something you can try; I don't know if it is relevant but try it. Do the following in T-SQL:
Then tell us what the result is.
Dipal ChoksiPosted Nov 7, 2011, 6:22 PM
Suthish NairPosted Nov 7, 2011, 3:40 PM
select ascii('ñ') ==> 241
Isidro PadillaPosted Nov 7, 2011, 8:43 AM
¿Alguien sabe como resolver este problema?
Translated into Engles:
Hello again everyone:
Does anyone know how to solve this problem?
Isidro PadillaPosted Nov 2, 2011, 6:52 AM
this.ExecuteSql("master", "CREATE DATABASE Elev");
this.ExecuteSql("Elev", this.GetSql("Scripts.Create_Tablas.txt"));
Pero no sé como cambiar estas líneas para corregir el problema.
ooooooooooooooooooOOOOOOOOOOOOOOOOOOoooooooooooooooooooo
Translate Into English:
Accents and special characters like "ñ" are altered by this instruction:
this.ExecuteSql ("master", "CREATE DATABASE Elev");
this.ExecuteSql ("Elev" this.GetSql ("Scripts.Create_Tablas.txt"));
I do not know how to change these lines to correct the problem.
Isidro PadillaPosted Nov 2, 2011, 4:00 AM
El Cambio varchar por nvarchar no resuelve el problema.
Translated into English:
Sam Hobbs thank you very much, I'll create a new table and do some tests.
Varchar for nvarchar Change does not solve the problem.
Sam HobbsPosted Nov 1, 2011, 7:52 PM
If however you are asking how to convert the existing data, then I am not sure. I am not experienced with SQL Server tools but I assume you can create a new table and then copy the data from the existing table to the new table.
If there is existing data that should be something different, such as the existing data should have accents and have special characters like "ñ" but they do not, then there is probably not an easy way to convert the data. You might need to get someone to do that "manually" in the sense of someone looking at each record and fixing anything that is incorrect.
Isidro PadillaPosted Nov 1, 2011, 5:49 PM
CREATE TABLE [dbo].[11PAISES](
[IdPais] [int] IDENTITY(1,1) NOT NULL,
[Nombre] [varchar](50) NOT NULL,
CONSTRAINT [PK_11PAISES] PRIMARY KEY CLUSTERED
Efectivamente el campo no es unicode. ¿Entonces cual es la solución cambiar el campo varchar por nvarchar?
Gracias de nuevo.
ooooooooooooooooooOOOOOOOOOOOOOOOOOOOoooooooooooooooooo
Translated into English:
Sam Hobbs thanks for answering, all the information in the database is in the attached draft, but I understand the lack of time you may have to revise it. So I provide you the structure of the tables gives me problems:
CREATE TABLE [dbo]. [11PAISES] (
[IdPais] [int] IDENTITY (1,1) NOT NULL,
[Name] [varchar] (50) NOT NULL,
CONSTRAINT [PK_11PAISES] PRIMARY KEY CLUSTERED
Indeed the field is not unicode. So what is the solution to change the varchar for nvarchar field?
Thank you again.
Sam HobbsPosted Nov 1, 2011, 4:30 PM