The configuration element is not declared

后端 未结 9 1481
死守一世寂寞
死守一世寂寞 2020-12-04 17:08

I\'m doing some work in Visual Studio 2012 Express Edition. I have added an App.config XML file as follows:

         


        
9条回答
  •  离开以前
    2020-12-04 18:01

    I also got the same warning. After thinking about for some time I realized my error working with SQL (MS SQL).

    Warning: the 'configuration' element is not declared
    

    Using C#

    App.Config code:

    
        
    
    

    *this calls out the database name in the connectionStrings, when I plugged in my SQL code as a practice I always use the database name, schema, then table. This practice didn't carry over well in Visual Studio as I am a beginner. I removed the db name from my SQL syntax and only called from the schema, data table. This resolved the issue for me.

    Form.CS:

     using (SqlCommand cmd = new SqlCommand("SELECT * FROM [DatabaseName].[Schema].[TableName] WHERE [MEPeriod] = '2020-06-01'", con))
    

    Updated to:

    using (SqlCommand cmd = new SqlCommand("SELECT * FROM [Schema].[TableName] WHERE [MEPeriod] = '2020-06-01'", con))
    

    This worked for me, I hope this is found as useful.

提交回复
热议问题