Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

{System.Configuration.ConfigurationErrorsException: easy question.

Posted on 2008-06-10
7
1,515 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

808 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