Configuración de la biblioteca

  1. I have a library project that accesses the database configured in app.config
  2. I have a web project that accesses the database configured in web.config

Both are working properly

Now I want to use the library from the web project. In Visual Studio works fine. In production server the web project access the database but the library not is capable of accessing the database from the project web.

The ConnectionString in app.config and web.config are identical. In production server should not take the web.config settings?

Gracias y perdón por mi inglés

EDITAR

web.config and app.config connectionStrings

<connectionStrings> 
    <add name="IntranetConnectionString" 
         connectionString="Data Source=(local)\SQLExpress;Initial Catalog=Intranet;Integrated Security=True;" 
         providerName="System.Data.SqlClient" /> 
    <add name="Database.Properties.Settings.IntranetConnectionString" 
         connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=Intranet;Integrated Security=True" 
         providerName="System.Data.SqlClient" /> 
</connectionStrings>

Error:

Se produjo un error relacionado con la red o específico de la instancia al establecer una conexión con SQL Server. El servidor no se encontró o no estaba accesible. Verifique que el nombre de la instancia sea correcto y que SQL Server esté configurado para permitir conexiones remotas. (proveedor: Interfaces de red SQL, error: 26 - Error al localizar el servidor / instancia especificada)

preguntado el 22 de mayo de 12 a las 21:05

but what's the error that your getting? could you show us the stacktrace? -

3 Respuestas

If I understand correctly, try copying local the reference of the libraries, to do this, right-click the reference in your project, then, in the properties, set True a Copy Local, now you will have the libraries locally in your server.

This should work if the problem is related to the references of the libraries, it won't help if it's a web.config/app.config problema

contestado el 22 de mayo de 12 a las 21:05

The problem not is references, is configuration. --- Spanish: El problema no es de referencias, es de configuración. - Leonardo

Could you post the .config files? - Luis

.... <connectionStrings> <add name="IntranetConnectionString" connectionString="Data Source=(local)\SQLExpress;Initial Catalog=Intranet;Integrated Security=True;" providerName="System.Data.SqlClient" /> <add name="Database.Properties.Settings.IntranetConnectionString" connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=Intranet;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> ..... - Leonardo

edit your question, and update your app.config in the question, not here - Jorge

The DLL generally takes the app.config of the host application that is calling it and not its own config. Is there some meat here?

contestado el 22 de mayo de 12 a las 21:05

When you publish it the config goes into [app_name].exe.config and not app.config, is that what's wrong? - edocetirwi

It is a web project (not exe). When I publish web.config is correct. The database access works fine from within the application but not from the DLL. The DLL is not taking web.config settings!! - Leonardo

La solución:

In the DLL create a class to access the DataTable with a constructor that receives the ConnectionString

public TestBLL(String ConnectionString)
{
    TestTableAdapter ta = new TestTableAdapter();
    ta.Connection = new System.Data.SqlClient.SqlConnection(ConnectionString);
}

In the Web project:

String cs = System.Configuration.ConfigurationManager.ConnectionStrings["IntranetConnectionString"].ToString();
TestBLL taBLL = new TestBLL(cs);

In taBLL have the methods to access each Query

contestado el 23 de mayo de 12 a las 05:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.