Error connecting SQL-SERVER with C #

0

Good morning everyone I have the following code to establish a connection to a database SQL-SERVER 2014 .

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;

namespace QDoc.Acceso
{
    class Conexion
    {
        //variable globales
        private static string cadenaconexion = ConfigurationManager.ConnectionStrings["cadenaconexion"].ConnectionString; // lee la cadena de conexión de la configuración de la aplicación

The detail is that when executing it sends me the following error:

The name 'ConfigurationManager' does not exist in the current context and use the options given to me and I can not correct the error, someone knows what I can do.

    
asked by Alberto Arenas 06.04.2017 в 17:44
source

2 answers

4

You must make sure to add the reference to the System.Configuration.dll assembly. In your project, right click and then in References (References), select Add reference (Add Reference) and, there you are looking for System.Configuration.

    
answered by 06.04.2017 / 17:52
source
1

Make sure you have the reference to System.Configuration added to the project, because sometimes it does not work just to add the using System.Configuration; statement:

If it does not appear, right click on the references tab itself and add the reference to System.Configuration.dll . Recompile the project and check that everything works correctly.

    
answered by 06.04.2017 в 18:00