Re: Maintaining and Using App Login details

From: Sijin Joseph (sijinNOSPAMdotnet_at_hotmail.com)
Date: 09/26/04


Date: Sun, 26 Sep 2004 20:05:57 +0530

I define the connection string in either the application config file
(app.config) or the registry and then use a class which exposes a static
method that returns the connection string.

For e.g.

public class Settings
{
        public static ConnectionString
        {
                get
                {
                        //Get the connection string either by using registry or by using
ConfigurationSettings.AppSettings class
                }
        }
}

Now in all the classes where i need a connection i simply use

SqlConnection conn = new SqlConnection(Settings.ConnectionString);

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

Craig - A Healtchare IT developer wrote:
> Hi,
>
> I'm developing an Windows forms based app that will draw data from a SQL
> Server 2000 system, that is set to use SQL Authentication (i.e. connection
> string must pass uname:pword).
>
> Given that various forms will need to use a SQL connection to generate data
> for data grid's etc ... how can I pass this authentication information around
> the various forms?
>
> A solution is to start the application from a VB.NET class, that has a
> shared member with the connection string (set once the user completes the
> login)
>
> Or create a shared connection object? Should I create a new connection
> object for each form?
>
> I currently test whether the login credentials are correct by enclosing
> within a try..catch clause an attempt to open and close a connection, failure
> will indicate invalid details (or perhaps a dead SQL Server!) ... any
> improvements on this?
>
> I assume that when using the form designer in VS.NET that if I manually
> program the connection (i.e. outside the section of code written by VS.NET )
> that I can point the adapters/datasets etc. to the required connection.
>
> There are a few questions here ... but I've not so far found any answers
> here, on Google or elsewhere :( !
>
> Thanks in advance for help
>
>



Relevant Pages

  • Re: [SOLVED] Cannot display provider-specific login prompt
    ... scenario where the program wouldn't have to know about the database, ... ConnectionStringBuilder up to a PropertyGrid for the end user to populate), ... details of the connection, for the sake of the program being able to connect ... information about the connection string that I will need. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Complicated Connection Problems bewteen ADP and SQL Server
    ... front end on the 5-8 workstations where the users happen to sit. ... expertise for getting the user workstations talking to the SQL Server. ... connection would fail and the adp wouldn't be able to talk to the server. ... thought that I should instead change my connection string to something ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Fujitsu NetCobol 8.0
    ... You cannot use a connection string in the way you have shown and expect it ... Any Fujitsu NetCobol / PowerCobol users here? ... Use the ADO control provided in PowerCOBOL, ...
    (comp.lang.cobol)
  • Re: Changing Connection String programmatically
    ... This is a good situation for putting the connection string information in the app.config file. ... every year we will create new database. ... change the body of the private void InitConnection(), ...
    (microsoft.public.sqlserver.connect)
  • Re: ASP.net and Oracle error System.Data.OleDb.OleDbException
    ... Also see http://www.connectionstrings.com/ and try other providers ... > Here is some of my connection code: ... >> And are you sure your connection string is ok. ... >>> Oracle error occurred, but error message could not be retrieved from ...
    (microsoft.public.dotnet.framework.aspnet)