Hi Vineet Here's the Solution you can try with this If any error please let me know.. Even i am using the same if any variables or something missing let me know
Just i have Declared Some *Global Variables* here [?]
Module GlbVariables
Public glb_DBUserid As String
Public glb_DBPassword As String
Public glb_DBName As String
Public glb_ServerName As String
End Module
*App.congif file connection String* [?]
<connectionStrings>
<add name="DefaultConnectionStringToMasterDatabase"
connectionString="Data Source=ServerName;Initial Catalog=Master;integrated
security=True;uid=UserName;pwd=Password"
providerName="System.Data.SqlClient" />
</connectionStrings>
*
'SQL DATA Manager Class *[?]
This Below Class uses the Master database Connection String and then
Connects to the Databse which is Stored in the Global Variable with UserId
and Password..
If any error in the code please let me know
Imports System.Data.SqlClient
Imports System.Configuration
Namespace DataManager
Public Class SqlServerDataManager
#Region "Private Attributes"
Private m_ConnectionString As String
Public m_Connection As SqlConnection
Private m_Command As SqlCommand
Private m_DataAdapter As SqlDataAdapter
Private m_CommandBuilder As SqlCommandBuilder
Private StrSql As String
#End Region
'Constructor
Public Sub New()
'In Below Line i have connected to the Master database this is
mandatory and after that we can build connectionstring Dynamically as shown
below
m_ConnectionString =
ConfigurationManager.ConnectionStrings("DefaultConnectionStringToMasterDatabase").ConnectionString
Dim ConnStrBuiler As New
SqlConnectionStringBuilder(m_ConnectionString)
Dim PrevYearConnStr Builer As New
SqlConnectionStringBuilder(m_ConnectionString)
Try
If Len(glb_DBName) <= 0 Then
m_Connection = New
Data.SqlClient.SqlConnection(m_ConnectionString)
Else
ConnStrBuiler.InitialCatalog = glb_DBName
m_Connection = New
Data.SqlClient.SqlConnection(ConnStrBuiler.ToString())
End If
glb_DBUserid = ConnStrBuiler.UserID
glb_DBPassword = ConnStrBuiler.Password
glb_ServerName = ConnStrBuiler.DataSource
glb_strConnString = ConnStrBuiler.ToString()
m_Command = New Data.SqlClient.SqlCommand
m_Command.Connection = m_Connection
m_Command.CommandType = CommandType.Text
Catch ex As System.InvalidOperationException
MessageBox.Show(ex.Message.ToString)
Catch ex As Exception
MessageBox.Show(ex.Message.ToString)
End Try
End Sub
'And a Test Query for the above code
'Wrote a function which Executes the Query sent as parameter and returns the
value
Public Function GetValue(ByVal SQL As String) As Object
' Function will return First-Row First-Column result of
executing SQL Query over Access Database
If m_Connection.State = ConnectionState.Open Then
m_Connection.Close()
End If
If SQL.Length <= 0 Then
Throw New InvalidExpressionException
End If
Dim oObject As Object
m_Command.CommandText = SQL
m_Command.CommandType = CommandType.Text
Try
m_Connection.Open()
oObject = m_Command.ExecuteScalar()
m_Connection.Close()
Return oObject
Catch ex As System.Data.SqlClient.SqlException
' Closing connection
Call CloseConnectionObject()
Throw New InvalidExpressionException(ex.Message.ToString)
Catch ex As System.InvalidOperationException
' Closing connection
Call CloseConnectionObject()
Throw New InvalidOperationException(ex.Message.ToString)
Catch ex As Exception
' Closing connection
Call CloseConnectionObject()
Throw New Data.DataException
Finally
' Closing connection
Call CloseConnectionObject()
End Try
End Function
Public Sub CloseConnectionObject()
' Closing connection
If m_Connection.State = ConnectionState.Open Then
m_Connection.Close()
End If
If Not IsNothing(m_DataAdapter) Then
m_DataAdapter.Dispose()
End If
If Not IsNothing(m_CommandBuilder) Then
m_CommandBuilder.Dispose()
End If
End Sub
End Class
End Namespace
I think this will help you a lot ..[?][?][?][?]
On Fri, Jul 3, 2009 at 10:07 PM, Vineet <[email protected]> wrote:
>
>
> ---------------------------------------------------------------------------------------------------------------
> 1) My application is Win Forms application. Not a web app.
>
> 2) Conn Strings will be built dynamically.
> (In short, each user will login with his/her ID and password to mysql
> through VB.NET WinForms, doint some work like adding records, fetching
> reports, ets., then logging off.) So connection string will be
> different for different users.
>
> 3) The reason as to WHY I maintain separate projects for separate
> forms---
> This is to simplify client-updates. I distribute only .exe files to my
> clients.
> If there is any bug in my code, I can send only a small .exe file
> pertaining to that Form. This way, customer servicing is very easy.
>
> What I Tried after my initial post --
> 1)Created a DLL project with public string property with user scope in
> Preferences--Settings.
> 2)This DLL is referenced in Login form project.
> 3) From Login form, this string property is modified to hold user's
> connection string.
> 4) This DLL is referred in all other projects requiring conn string.
>
> .......and this works.......
> I hope there will not be any security threat for capturing login info
> by any malicious lifeform !!
>
> Any ideas for the betterment of the Solution?
>
> Thanks,
> Vineet.
>
> ---------------------------------------------------------------------------------------------------------------
--
Thanks & Regards
Avinash Desai
*SAVE Nature SAVE Tree SAVE*
Think Before you print: Please consider our environment before printing this
e-mail
Adrienne
Gusoff<http://www.brainyquote.com/quotes/authors/a/adrienne_gusoff.html>
- "Opportunity knocked. My doorman threw him out."
<<inline: 332.gif>>
<<inline: 981.gif>>
<<inline: 360.gif>>
<<inline: 983.gif>>
