Solved

{System.Configuration.ConfigurationErrorsException: easy question.

Posted on 2008-06-10
7
1,495 Views
Last Modified: 2013-12-17
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
Comment
Question by:mathieu_cupryk
  • 3
  • 2
  • 2
7 Comments
 
LVL 19

Expert Comment

by:elimesika
ID: 21754917
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
 

Author Comment

by:mathieu_cupryk
ID: 21754954
{"Object reference not set to an instance of an object."}
0
 
LVL 19

Expert Comment

by:elimesika
ID: 21754999
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 19

Expert Comment

by:elimesika
ID: 21755009
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
 
LVL 14

Accepted Solution

by:
ajitha75 earned 500 total points
ID: 21755408
Try

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

You have to pass the name of the connection string and not the connection string itself.
0
 

Author Comment

by:mathieu_cupryk
ID: 21756167
anyone else?
0
 
LVL 14

Expert Comment

by:ajitha75
ID: 21756614
Also, your connection string is missing initial catalog attribute, which will define the database that it has to point to
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now