About SqlConnection String in App.config file
-
:confused::((Hi sir, I wrote a app.config as follows I called that connection string like this, SqlConnection cn; sConn = System.Configuration.ConfigurationManager.AppSettings("dbconnection"); cn = new SqlConnection(sConn); cn.Open(); then it is an error : The type or namespace name 'ConfigurationManager' does not exist in the class or namespace 'System.Configuration' (are you missing an assembly reference?) I am a beginner for c# can you help me? thank you
-
:confused::((Hi sir, I wrote a app.config as follows I called that connection string like this, SqlConnection cn; sConn = System.Configuration.ConfigurationManager.AppSettings("dbconnection"); cn = new SqlConnection(sConn); cn.Open(); then it is an error : The type or namespace name 'ConfigurationManager' does not exist in the class or namespace 'System.Configuration' (are you missing an assembly reference?) I am a beginner for c# can you help me? thank you
Collapse your project in the Solution Explorer window and right click 'References' and choose 'Add Reference'. A popup window appears, on the .NET tab, choose System.Configuration and press the OK button. Try rebuilding your project ;-)
- - - --[ i love it when a plan comes together ]-- - - -
-
:confused::((Hi sir, I wrote a app.config as follows I called that connection string like this, SqlConnection cn; sConn = System.Configuration.ConfigurationManager.AppSettings("dbconnection"); cn = new SqlConnection(sConn); cn.Open(); then it is an error : The type or namespace name 'ConfigurationManager' does not exist in the class or namespace 'System.Configuration' (are you missing an assembly reference?) I am a beginner for c# can you help me? thank you
mwith wrote:
Hi sirs and madams,
(fixed that for ya) You need to have: using System.Configuration; at the top of your code file. You might also need to explicitly add the reference to the System.Configuration assembly to your project. (Right-click on 'References' in the solution explorer, and click 'Add Reference...', then select the System.Configuration assembly, which is under the .Net tab in the window that pops up, and add that assembly to your project.) You will need to add a name attribute to your config file entry, or the app can't tell what you mean by 'dbconnection'. I do it like this: <appSettings> <add key="dbconnection" value="myconnectionstringwhateveritis"/> </appSettings> Also, I hope you didn't just give us all your SA login info. You need to change that right away if you did.
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps! -
Collapse your project in the Solution Explorer window and right click 'References' and choose 'Add Reference'. A popup window appears, on the .NET tab, choose System.Configuration and press the OK button. Try rebuilding your project ;-)
- - - --[ i love it when a plan comes together ]-- - - -
-
Hi I tried that, but there is no just System.Configuration. it has System.Configuration.install.dll I add that. but same error is coming. thanks
That means you already added it, and you just need the Using statement I mentioned.
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps! -
mwith wrote:
Hi sirs and madams,
(fixed that for ya) You need to have: using System.Configuration; at the top of your code file. You might also need to explicitly add the reference to the System.Configuration assembly to your project. (Right-click on 'References' in the solution explorer, and click 'Add Reference...', then select the System.Configuration assembly, which is under the .Net tab in the window that pops up, and add that assembly to your project.) You will need to add a name attribute to your config file entry, or the app can't tell what you mean by 'dbconnection'. I do it like this: <appSettings> <add key="dbconnection" value="myconnectionstringwhateveritis"/> </appSettings> Also, I hope you didn't just give us all your SA login info. You need to change that right away if you did.
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!With a password like that he'd want to change it even if he hadn't posted it on the internet. I'm assuming that he's changed it to sa like i would change mine to pwd if posting stuff on a forum. Reminds me of a place i worked where the head of IT was one of the owners of the company. While searching for some info about recordsets on usenet i saw a post of his from 5 years before. I duly went to have a look and found a username and password URL and port in his example code. I then discovered that not only had he not changed the password for this account but it was on a server that was still exposed to the internet and had domain admin permissions on our internal network. When i asked him about it, he said "That account, oh we haven't used it for ages, why do you ask". sorry for the OT, Russ
-
mwith wrote:
Hi sirs and madams,
(fixed that for ya) You need to have: using System.Configuration; at the top of your code file. You might also need to explicitly add the reference to the System.Configuration assembly to your project. (Right-click on 'References' in the solution explorer, and click 'Add Reference...', then select the System.Configuration assembly, which is under the .Net tab in the window that pops up, and add that assembly to your project.) You will need to add a name attribute to your config file entry, or the app can't tell what you mean by 'dbconnection'. I do it like this: <appSettings> <add key="dbconnection" value="myconnectionstringwhateveritis"/> </appSettings> Also, I hope you didn't just give us all your SA login info. You need to change that right away if you did.
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!That's not really true, it would be neat though, but as you can see in his code, het uses the entire namespace in his code : System.Configuration.ConfigurationManager.AppSettings["name"] which does not require a 'using' statement, but again... it would be neat...
- - - --[ i love it when a plan comes together ]-- - - -
-
That's not really true, it would be neat though, but as you can see in his code, het uses the entire namespace in his code : System.Configuration.ConfigurationManager.AppSettings["name"] which does not require a 'using' statement, but again... it would be neat...
- - - --[ i love it when a plan comes together ]-- - - -
Yeah you're right... I totally missed that. I think he's using .Net 1.1, but I can't remember what the difference was. With a .Net 2.0 project, it should be working if the assembly is added like he said.
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps! -
Yeah you're right... I totally missed that. I think he's using .Net 1.1, but I can't remember what the difference was. With a .Net 2.0 project, it should be working if the assembly is added like he said.
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!Erhm, you don't have the configurationmanager object there... The .NET 1.1 ols fashion way is System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"] (or ofcourse) using System.Configuration; and ConfigurationSettings.AppSettings["ConnectionString"]
- - - --[ i love it when a plan comes together ]-- - - -
-
:confused::((Hi sir, I wrote a app.config as follows I called that connection string like this, SqlConnection cn; sConn = System.Configuration.ConfigurationManager.AppSettings("dbconnection"); cn = new SqlConnection(sConn); cn.Open(); then it is an error : The type or namespace name 'ConfigurationManager' does not exist in the class or namespace 'System.Configuration' (are you missing an assembly reference?) I am a beginner for c# can you help me? thank you
What version of visual studio / .NET Framework are you using. The code you have will only work in .NET 2.0 (Visual Studio 2005). Also, replace the
()
with[]
afterAppSettings
because once you've fixed this error your going to get another.
Upcoming Scottish Developers events: * We are starting a series of events in Glasgow in 2007. Are you interested in a particular subject, or as a speaker? * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog | Photos