Solved

{System.Configuration.ConfigurationErrorsException: easy question.

Posted on 2008-06-10
7
1,520 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
Technology Partners: 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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

756 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