1

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

<connectionStrings>
    <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=***" />
  </connectionStrings>

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
        {
            get
            {
                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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.