Welcome to Comunidad .NET de Cd. Juárez Sign in | Join | Help

Browse by Tags

All Tags » sql   (RSS)
Web.Config(.net , sql) for noovies / para novatos

The last days some mates at work told that my post aren´t technical just off-topics :D, I think that developer's work, and work in the technology world is more than tech it has a lot of things around and mixing all you will get better results than if you just take the tech way.

Estos últimos dias compañeros en el trabajo me dijeron que mis post no son técnicos son más fuera de este tema, Pienso que el trabajo de un desarrollador y el trabajo en el mundo de la tecnología es más que tecnología, tiene muchas cosas alrededor y mezclandolas todas tendrás mejores resultados que si solo coges el camino tecnológico.

 So comming back with the post's topic I will write a little bit about ConnectionStrings with .net and sql

Bueno volviendo al tema del post ahora voy a contar un poco sobre cadenas de conexión o ConnectionStrings trabajando con .net y bases de datos sql.

 
 ConnectionStrings are inside of the tag <appSettings> in the web.config . Inside of this tag we can have keys (variables) which we could use in a general way in all our website and If some is changed in the configuration's parameters you just will have to change the web.config file.

Los ConnectionStrings estan dentro del campo <appSettings> del web.config . Dentro de este campo podemos añadir también claves (variables) que podremos usar de forma general en todo el sistema y que posteriormente solo tendremos que cambiar en el web.config para que afecte a toda nuestra web.

The motivation of declare this kind of variables in the webconfig is simple, you don't need compile again when you have your website is in production. I you have this important values in the code you should compile and generate the project again. So the change in the web.config is faster and more reliable.
 

El porque de declarar este tipo de variables en el webconfig es muy sencillo, ya que evitas tener que volver a generar el proyecto que ya está en producción, ya que si tuvieras estos valores en código lo deberias hacer, y el cambio en el web.config es más rápido y fiable. 

 

============================================
Examples / Ejemplos

 ===========================================

A simple connection string between .net and a sql database / Una cadena de conexión simple entre .net y una base de datos sql

<add key="Name_of_our_ConnectionString" value="web's workstation id" or IP ( in quotation marks ) ;packet size=4096;user id=NombreUsuarioBBDD;pwd=PasswordUsuario;data source="database's workstation id" or IP of the computer where the database is( in quotation marks );persist security info=False;initial catalog=nombre_de_la_BBDD" />

<add key="Nombre_de_nuestro_ConnectionString" value="Identificador de la máquina sobre la que esta trabajando la web" o IP (Entre comillas simples) ;packet size=4096;user id=NombreUsuarioBBDD;pwd=PasswordUsuario;data source= IP del equipo donde se encuentra la bbdd a la que accedemos desde nuestra web(Entre comillas simples);persist security info=False;initial catalog=nombre_de_la_BBDD" /> 

In the same web.config can be  more than one ConnectionString

 En un mismo web.config puede haber varias cadenas de conexión
 

  Declaring variables in web.config / Declarando variables en el web.config

       <add key="Name_Variable_WConfig" value="whatever string" /> (inside of appsettings)

      <add key="Nombre_Variable_WConfig" value="El string que quieras" /> (dentro de appsettings)



 Using the variables of web.config(appsettings) in your c# code / usando las variables del web.config (appsettings) en tu código c#

 Local_Variable=System.Configuration.ConfigurationSettings.AppSettings["Name_Variable_WConfig"];
 

sorry for my english, regards, salu2