Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1589
  • Last Modified:

{System.Configuration.ConfigurationErrorsException: easy question.

The requested database Data Source=SCWB2.WPG.CWB.CA;Persist Security Info=True;User ID=mxcupryk;Password=xxxx;Unicode=True is not defined in configuration.


 try
                {
                    // Create the Database object, using the default database service. The
                    // default database service is determined through configuration.

                    Database db = DatabaseFactory.CreateDatabase(ConfigurationManager.ConnectionStrings["InitialPrices.Properties.Settings.ConnectionString"].ConnectionString);  // Crashes here.


                    // Create the DbCommand object
                    DbCommand dbCommand = db.GetStoredProcCommand("insert_price_list_hdr");
                    dbCommand.CommandTimeout = 180;
                   
                    db.AddInParameter(dbCommand, "@p_price_list_hdr_id", DbType.String, txtCropYear.Text + txtListNo.Text);
                    db.AddInParameter(dbCommand, "@p_wht_tough_disc_amt", DbType.Decimal, 0.0);
                    db.AddInParameter(dbCommand, "@p_wht_damp_disc_amt", DbType.Decimal, 0.0);
                    db.AddInParameter(dbCommand, "@p_wht_stone_disc_amt", DbType.Decimal, 0.0);

                    db.AddInParameter(dbCommand, "@p_durum_tough_disc_amt", DbType.Decimal, 0.0);
                    db.AddInParameter(dbCommand, "@p_durum_damp_disc_amt", DbType.Decimal, 0.0);
                    db.AddInParameter(dbCommand, "@p_durum_stone_disc_amt", DbType.Decimal, 0.0);

                    db.AddInParameter(dbCommand, "@p_bly_tough_disc_amt", DbType.Decimal, 0.0);
                    db.AddInParameter(dbCommand, "@p_bly_damp_disc_amt", DbType.Decimal, 0.0);
                    db.AddInParameter(dbCommand, "@p_bly_stone_disc_amt", DbType.Decimal, 0.0);

                    db.AddInParameter(dbCommand, "@p_desigtd_bly_tough_disc_amt", DbType.Decimal, 0.0);
                    db.AddInParameter(dbCommand, "@p_desigtd_bly_damp_disc_amt", DbType.Decimal, 0.0);

                    db.AddInParameter(dbCommand, "@p_price_list_status_type_name", DbType.String, 0.0);
                    db.AddInParameter(dbCommand, "@p_load_dtm", DbType.DateTime, System.DateTime.Now);
                    db.AddInParameter(dbCommand, "@p_user_name", DbType.String, "Mathieu");


                    db.AddInParameter(dbCommand, "@p_wht_indr_flag", DbType.String, "1");
                    db.AddInParameter(dbCommand, "@p_durum_indr_flag", DbType.String, "1");
                    db.AddInParameter(dbCommand, "@p_bly_indr_flag", DbType.String, "1");
                    db.AddInParameter(dbCommand, "@p_desigtd_bly_indr_flag", DbType.String, "1");

                    db.AddInParameter(dbCommand, "@p_load_type_name", DbType.String, "Adjustment");
                    db.AddInParameter(dbCommand, "@p_pool_part_code", DbType.String, "1");
                    db.AddInParameter(dbCommand, "@p_sct_price_list_name", DbType.String, "1");
                    db.AddInParameter(dbCommand, "@p_row_cnt_qty", DbType.Decimal, "1");
                    db.AddInParameter(dbCommand, "@p_price_sum_amt", DbType.Decimal, 0);
                    db.ExecuteNonQuery(dbCommand);
                   
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }


The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource 'file:///C:/Documents and Settings/mxcupryk/Local Setti...

   at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.ValidateConnectionStringSettings(String name, Con...


{"The requested database Data Source=SCWB2.WPG.CWB.CA;Persist Security Info=True;User ID=mxcupryk;Password=abcd;Unicode=True is not defined in configuration."}

The requested database Data Source=SCWB2.WPG.CWB.CA;Persist Security Info=True;User ID=mxcupryk;Password=abcd;Unicode=True is not defined in configuration.

{Name = "DatabaseConfigurationView" FullName = "Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView"}

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="InitialPrices.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <connectionStrings>
        <add name="InitialPrices.Properties.Settings.ConnectionString"
            connectionString="Data Source=SCWB2.WPG.CWB.CA;Persist Security Info=True;User ID=mxcupryk;Password=xxxx;Unicode=True"
            providerName="System.Data.OracleClient" />
    </connectionStrings>
    <applicationSettings>
        <InitialPrices.Properties.Settings>
            <setting name="InitialPrices_InitialPriceReportingWS_InitialPriceReportingService"
                serializeAs="String">
                <value>http://localhost:50300/InitialPriceReportingService/InitialPriceReportingService.asmx</value>
            </setting>
        </InitialPrices.Properties.Settings>
    </applicationSettings>
</configuration>

Open in new window

0
mathieu_cupryk
Asked:
mathieu_cupryk
  • 3
  • 2
  • 2
1 Solution
 
elimesikaCommented:
HI

You have mistaken name , use code below :

The name used in the configuration file is : "InitialPrices.Properties.Settings"
You had : "InitialPrices.Properties.Settings.ConnectionString"
  Database db = DatabaseFactory.CreateDatabase(ConfigurationManager.ConnectionStrings["InitialPrices.Properties.Settings"].ConnectionString); 

Open in new window

0
 
mathieu_cuprykAuthor Commented:
{"Object reference not set to an instance of an object."}
0
 
elimesikaCommented:
HI

I want to check if there is a problem with the dots in the name , can you change the name to simply "A" in the config file and also the code to:
Database db = DatabaseFactory.CreateDatabase(ConfigurationManager.ConnectionStrings["A"].ConnectionString); 

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
elimesikaCommented:
config file section :
 <connectionStrings>
        <add name="A"
            connectionString="Data Source=SCWB2.WPG.CWB.CA;Persist Security Info=True;User ID=mxcupryk;Password=xxxx;Unicode=True"
            providerName="System.Data.OracleClient" />
    </connectionStrings>

Open in new window

0
 
ajitha75Commented:
Try

DatabaseFactory.CreateDatabase("InitialPrices.Properties.Settings.ConnectionString")

You have to pass the name of the connection string and not the connection string itself.
0
 
mathieu_cuprykAuthor Commented:
anyone else?
0
 
ajitha75Commented:
Also, your connection string is missing initial catalog attribute, which will define the database that it has to point to
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now