How to use the ConfigurationManager.AppSettings

前端 未结 4 1174
囚心锁ツ
囚心锁ツ 2021-01-30 21:12

I\'ve never used the \"appSettings\" before. How do you configure this in C# to use with a SqlConnection, this is what I use for the \"ConnectionStrings\"

SqlCon         


        
4条回答
  •  被撕碎了的回忆
    2021-01-30 21:31

    \if what you have posted is exactly what you are using then your problem is a bit obvious. Now assuming in your web.config you have you connection string defined like this

     
    

    In your code you should use the value in the name attribute to refer to the connection string you want (you could actually define several connection strings to different databases), so you would have

     con.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
    

提交回复
热议问题