Solved

ASP.net AppSettings & Connection Strings

Posted on 2006-06-26
5
700 Views
Last Modified: 2012-06-27
Here is a very strange problem I'm having. I built an application that is working fine. The connection string works and now I want to move the connection strings to the web.config file.

Before in my InitializeComponent Method (which Works):

this.sqlConnectionDatabase.ConnectionString = "Data Source=servername; Initial Catalog=dbsystemodbc; Persist Security Info=True;User ID=sa;Password=MyPassword";

Now I changed it and placed the following in my webconfig:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
      <appSettings>
            <add key="odbcConnectionString" value= "Data Source=servername; Initial Catalog=dbsystemodbc; Persist Security Info=True;User ID=sa;Password=MyPassword"/>
      </appSettings>

I then changed my InitializeComponent to the following

this.sqlConnectionDatabase.ConnectionString = WebConfigurationManager.AppSettings["odbcConnectionString"];

But this does not work. It fails on the sqlConenctionDatabase.Open();

I have looked at what is returned by the WebConfigurationManager.AppSettings and it looks exactly like the direct string I placed in the connnectionstring property. But if I compare the two strings, the system returns that they are not the same. Also used the ConfigurationSettings.AppSettings["odbcConnectionString"], and got the same results.

Why is this not working? Are there control characters placed in the output of the AppSettings?

My next step is to encrypt, but I cant even get the clear text version from AppSettings to work.

Thanks
0
Comment
Question by:josephbarron
[X]
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
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
ayha1999 earned 250 total points
ID: 16987299
hi
try this

<add key="odbcConnectionString" value="server=servername;database=databsename;User ID=sa;password=mypassword;trusted_connection=False;"/>

this.sqlConnectionDatabase.ConnectionString = ConfigurationSettings.AppSettings["odbcConnectionString"];

ayha
0
 
LVL 7

Expert Comment

by:ayha1999
ID: 16987311
You have to import the fllowing name space.

system.configuration


ayha
0
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 250 total points
ID: 16987405
ayha1999, in .NET 2.0 ConfigurationSettings has been replaced by WebConfigurationManager


 josephbarron, did you try debugging?
What value do you get in this.sqlConnectionDatabase.ConnectionString?

use try...catch blocks:

try{
      sqlConenctionDatabase.Open();

}catch (Exception e) {
       Console.Write(e);
}
0
 
LVL 35

Expert Comment

by:YZlat
ID: 16987532
I got it! you misspelled sqlConenctionDatabase
0
 

Expert Comment

by:SathyaPrabha
ID: 16999781
Hai,


Try this.



<appSettings>
<add key = "ConnectionInfo" value = "Server=UrServer;uid=sa;password=Urpwd;database=Northwind;"/>
</appSettings>

Dim constr As String
Dim con As SqlConnection

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        constr = ConfigurationSettings.AppSettings("ConnectionInfo")
        con = New SqlConnection(constr)
        con.Open()

End Sub

Sathya
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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