?
Solved

ASP.net AppSettings & Connection Strings

Posted on 2006-06-26
5
Medium Priority
?
703 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 750 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 750 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

801 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