Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: 23 Apr 2006 00:12:59 -0700,    group: microsoft.public.dotnet.datatools        back       


why store a user's connection string in appsettings?   
I'm transitioning to ado.net from ado, and I'm having a hard time with
the apparent "best practice" of storing connection strings in an
application's settings file (app.exe.config). I can't think of a single
app I've ever written where I'd want a hard-coded connection string:
the first step in most of my data-based apps is to select and log into
a database.

But all the "best practive" data access methods I'm encountering
(creating a strongly typed DataSet, for example, or using the Data
Access Application Block) are built off a hard-coded connection string.
I'm creating a class library to encapsulate data access to a particular
database, but I have no way of passing it a connection string, since it
runs with the connection string it was compiled with. That's just
goofy. But it seems like all the demo apps I'm finding fit that
paradigm.

What am I missing? Something pretty basic, I'm sure. Can the
application's configuration be updated by the application itself? (I
don't see how, since App-scope settings are read-only.)

Philosophically, does anyone really distribute applications with
embedded connection strings? Am I correct in thinking that without a
connection string in app.config, the DAAB is unusable?

Thanks for enlightening me.

g.
date: 23 Apr 2006 00:12:59 -0700   author:   Graham Charles

Re: why store a user's connection string in appsettings?   
Hello Graham,

GC> But all the "best practive" data access methods I'm encountering
GC> (creating a strongly typed DataSet, for example, or using the Data
GC> Access Application Block) are built off a hard-coded connection
GC> string. I'm creating a class library to encapsulate data access to a
GC> particular database, but I have no way of passing it a connection
GC> string, since it runs with the connection string it was compiled
GC> with. That's just goofy. But it seems like all the demo apps I'm
GC> finding fit that paradigm.

      It's just to keep the samples simple

GC> What am I missing? Something pretty basic, I'm sure. Can the
GC> application's configuration be updated by the application itself? (I
GC> don't see how, since App-scope settings are read-only.)

      Idea in changing this data manually, without recompiling your app. 

GC> Philosophically, does anyone really distribute applications with
GC> embedded connection strings? Am I correct in thinking that without a
GC> connection string in app.config, the DAAB is unusable?

       No, just keep your connection string in external file 

---
WBR,
Michael  Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not 
cease to be insipid." (c) Friedrich Nietzsche
date: Sun, 23 Apr 2006 11:59:53 +0000 (UTC)   author:   Michael Nemtsev

Re: why store a user's connection string in appsettings?   
Michael, thanks for your reply. I'm still quite baffled, though.

MN> Idea in changing this data manually, without recompiling your app.

Um, but it's the application (well, the user running the application)
that I want to have select a connection (not to mention enter their own
password). Since the application can't update application-scope
settings, I'm confused about what you mean by "manually."

MN> No, just keep your connection string in external file

Well, setting aside for a moment that I don't really want connection
data persisted to disk (I'll assume there's an encryption methodology
I've not yet run across), I've not found an example of how to make this
work. The code for the DAAB to connect to a database ---
DatabaseFactory.CreateDatabase() --- will use the connection string in
the running application's app.config (e.g. application.exe.config). I
suppose I could write a helper "login" application that would accept a
user's connection information (server, user id, password), write it to
the .config file (encrypting it, I'd hope), and then start up the main
application... is that how it's usually done, then?

g.
date: 23 Apr 2006 13:30:20 -0700   author:   Graham Charles

Re: why store a user's connection string in appsettings?   
The DAAB also allows the connection string information to be encrypted.

"Graham Charles"  wrote in message 
news:1145824220.881016.262300@i40g2000cwc.googlegroups.com...
> Michael, thanks for your reply. I'm still quite baffled, though.
>
> MN> Idea in changing this data manually, without recompiling your app.
>
> Um, but it's the application (well, the user running the application)
> that I want to have select a connection (not to mention enter their own
> password). Since the application can't update application-scope
> settings, I'm confused about what you mean by "manually."
>
> MN> No, just keep your connection string in external file
>
> Well, setting aside for a moment that I don't really want connection
> data persisted to disk (I'll assume there's an encryption methodology
> I've not yet run across), I've not found an example of how to make this
> work. The code for the DAAB to connect to a database ---
> DatabaseFactory.CreateDatabase() --- will use the connection string in
> the running application's app.config (e.g. application.exe.config). I
> suppose I could write a helper "login" application that would accept a
> user's connection information (server, user id, password), write it to
> the .config file (encrypting it, I'd hope), and then start up the main
> application... is that how it's usually done, then?
>
> g.
>
date: Mon, 24 Apr 2006 13:11:59 +1000   author:   Brendan Green

Re: why store a user's connection string in appsettings?   
Thanks for your reply, Brendan; I did assume that encryption would be
involved. My more pressing need is to be able to set the connection
string in the first place, which seems to be impossible, since
Application-scope settings are read-only.
date: 24 Apr 2006 13:59:34 -0700   author:   Graham Charles

Re: why store a user's connection string in appsettings?   
OK, I figured it out. The answer is not to use "DatabaseFactory" to
provide a database object unless your server location is essentially
fixed. By using DatabaseFactory.CreateDatabase, you are limited to the
database connections enumerated in app.config (a.k.a.
application.exe.config), so to change database targets requires
redistributing that file. By contrast, if you instantiate a SqlDatabase
object in the DAAB's "SQL" namespace, which derives from DAAB's
Database object, you can use a user-specified connection string
(whether from My.Settings, an input form, etc.)

Here's an example. I'm going to use an explicitly named Imports
statement so that's obvious that I'm not going for the
Microsoft.System.Data objects (SqlDatabase and Database).

Imports DAAB = Microsoft.Practices.EnterpriseLibrary.Data

Sub MakeConnection()
    Dim db As DAAB.Sql.SqlDatabase = New
DAAB.Sql.SqlDatabase(MyConnectionString)
End Sub


Now, was that so hard?

Sheesh.

g.
date: 8 May 2006 16:38:18 -0700   author:   Graham Charles

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us