MS SQL Server
  Home arrow MS SQL Server arrow Page 3 - A Secure Way of Building Connection String...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

A Secure Way of Building Connection Strings
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2006-11-14

    Table of Contents:
  • A Secure Way of Building Connection Strings
  • Reviewing member properties of the class
  • Reviewing properties using an example
  • Building a ConnectionString using the class
  • Entering valid connection information

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    A Secure Way of Building Connection Strings - Reviewing properties using an example


    (Page 3 of 5 )

    Add a command button to the Properties.vb form. Insert the contents of the following listing to the click event of the button as shown. The code is adequately commented to explain the various statements in this listing. An existing connection string provides the argument for the constructor of the class, and then looks at the default values of other related properties of the string. Then a complete string is provided and the constituent key/value pairs are accessed programmatically.

    Imports System
    Imports System.Data.SqlClient
    Imports System.Collections Public Class Properties Private Sub 
    Button1_Click(ByVal sender As System.Object, _ ByVal e As System.

    EventArgs)
    Handles Button1.Click 'Instantiate a SQL connection string builder 'called() 'myBuilder' with an argument that is 'provided by the function, GetConnString() Dim myBuilder
    As New _ SqlConnectionStringBuilder(GetConnString()) 'print out the
    connection string
    Debug.Print(myBuilder.ConnectionString) ' provide
    an existing connections string to ' SqlConnectionStringBuilder and you can retrieve and ' modify any of the elements.
    myBuilder.ConnectionString = _ "server=(local); user id=sa;" & _ "password=XXXXXXX; initial catalog=Northwind" Debug.Print ("Password: " & _ myBuilder.Password & vbCrLf) Debug.Print ("Security Info Persist: " & _ myBuilder.PersistSecurityInfo & vbCrLf) Debug.Print ("Connection Timeout: " & _ myBuilder.ConnectTimeout & vbCrLf) Debug.Print ("Current Language: " & _ myBuilder.CurrentLanguage & vbCrLf) Debug.Print ("Initial Catalog: " & _ myBuilder.InitialCatalog & vbCrLf) Debug.Print ("Asynchronous Processing(yes/no): " & _ myBuilder.AsynchronousProcessing & vbCrLf) Debug.Print ("Data Source: " & _ myBuilder.DataSource & vbCrLf) End Sub Private Function
    GetConnString() As String Return "Server=(local); Integrated Security=SSPI;" & _ "Initial Catalog=Northwind" End Function End Class

    The coding is made easier since you have complete intellisense support by way of a drop-down listing of object related information as shown in the next picture.

    The Debug.print output from the code is run when the button is clicked, as shown in the next paragraph. The password came out in clear text, which has been replaced by 'XXXXX' in this document.

    Data Source=(local);Initial Catalog=Northwind; Integrated Security=True
    Password: XXXXXX Security Info Persist: False Connection Timeout: 15 
    Current Language: Initial Catalog: Northwind Asynchronous
    Processing(yes/no)
    : False Data Source: (local)

    More MS SQL Server Articles
    More By Jayaram Krishnaswamy


       · Security is one of the most important concerns and the hassle free SQL Connection...
     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway