Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

XSD Connection String

Posted on 2006-05-16
8
Medium Priority
?
1,473 Views
Last Modified: 2008-12-12
I have a class library project that has multiple XSD files. The Connection String is set in the app.config. Is there any way to change the connection string during runtime? Right now i have to modify the settings and app.config before compiling and putting it on my web servers.

Thank you
0
Comment
Question by:irmsystems
  • 3
5 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 200 total points
ID: 16694629
Hi irmsystems,

if you need to write to your app.config file this entry shows how
source: http://ryanfarley.com/blog/archive/2004/07/13/879.aspx

hope this helps a bit
bruintje
0
 
LVL 11

Assisted Solution

by:anyoneis
anyoneis earned 200 total points
ID: 16695168
There are a couple of approaches to dealing with Connection Strings. The first will work with 2003 and 2005:

In your app settings section in App.Config, put in the production values for connection strings, but add a "file=" attribute, as in:

   <appSettings file="MyspecialAppSettings.config">
          <add key="CS" value="connectionstring_stuff"/>          
     </appSettings>

Then, in the binary directory on the server, place the file MyspecialAppSettings.config. In there, place an unadorned appsettings section, as in:

   <appSettings >
          <add key="CS" value="otherconnectionstringstuff"/>          
     </appSettings>

That doesn't change it during runtime, but it does give you a way to leave app.config alone.

If this is using a stringly typed dataset in VS2005, I know of a method mentioned in "Data Binding with Windows Forms 2.0" by Brian Noyes which lets you change the cs at runtime.

David
0
 

Author Comment

by:irmsystems
ID: 16699300
This is using a strongly typed dataset in VS2005 in ASP.NET application.
0
 
LVL 11

Expert Comment

by:anyoneis
ID: 16700834
OK, so the SqlConnection object on the table adapter is Internal access- that is, only code in the same assembly has access. So, you just need to add a simple class to the module containing the dataset (ideally, it is a separate DataAccessLayer DLL) that can access the connection objects, allowing you to query and change the connections at run time. The class will contain (and I paraphrase from Brian Noyes excellent and highly recommended book "Data Binding with windows Forms 2.0" on page 61):

using System.Data.SqlClient;
using YourDataAccessLayerNamespace.YourDataSetTableAdapters;

namespace YourDataAccessLayerNamespace
{
    public class YourTableNameTableAdapterConnectionManager
   {
      public static SqlConnection GetConnection(YourTableNameTableAdapter adapter)
      {
         return adapter.Connection;        
      }

      public static void SetConnection(YourTableNameTableAdapter adapter, SqlConnection connection)
      {
         adapter.Connection = connection;
      }
   }
}

You use the GetConnection and SetConnection methods to get the SQLConnection object so that you can control the connection string.

Is this clear?

David
0
 
LVL 11

Expert Comment

by:anyoneis
ID: 16944408
Absent feedback, split the points? I think bruintje and I covered the bases pretty well.

David
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

572 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