I have a sharepoint code, where I use connection to sql database, when I use a string to connect it works,

 string connstr = "Data Source=CH-SQLD;Initial Catalog=LOGS;User ID=***;Password=***";
 DataProviderUtility.ExecuteStoredProcedureToSqlDatabase(sqlParam, StoredProcedures.CREATELOG, connstr);

but when I added a file app.config

    <add name="BankGuarantee" connectionString="Data Source=CH-SQLD;Initial Catalog=BG;User ID=***;Password=***" />
    <add name="SalesReport" connectionString="Data Source=CH-SQLD;Initial Catalog=SALES;User ID=***;Password=***" " />
    <add name="Logging" connectionString="Data Source=CH-SQLD;Initial Catalog=LOGS;User ID=***;Password=***" />
    <add name="ExchangeRate" connectionString="Data Source=CH-SQLD;Initial Catalog=COMMON;User ID=***;Password=***" />

to my solution and set connectionString in it and I try to call it

 DataProviderUtility.ExecuteStoredProcedureToSqlDatabase(sqlParam, StoredProcedures.CREATELOG, ConnectionStringValues.LoggingConnectionString);

Where LoggingConnectionString is :

 public static string LoggingConnectionString
                if (string.IsNullOrEmpty(logging))
                    logging = ConfigurationManager.ConnectionStrings[CONNECTIONKEY_LOGGING].ConnectionString;

                return logging;

I know that we have posts for the same issue like https://stackoverflow.com/questions/6536715/get-connection-string-from-app-config but it doesn't solve my problem it throws exception : {"Object reference not set to an instance of an object."} In my ProjectName.dll.config I can see my connectionString

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.