Thanks Frinny for following it up.
For making DB connection, I have placed my connectionString in web.config as:
- <connectionStrings>
-
<add name="MyDBConnection" connectionString="server=Server1; database=Req1; uid=sa; pwd=;" />
-
</connectionStrings>
Now I have created a seperate project "DBConnect" and in the Class file DBConnect.vb I was writing this function for connecting to DB as:
- Public Shared Function getConnectionObj() As SqlConnection
-
Dim objSqlConn as SqlConnection
-
Dim strConn as string
-
-
strConn = ConfigurationManager.ConnectionStrings("MyDBConnection").ConnectionString
-
-
objSqlConn = New SqlConnection(strConn)
-
-
End Function
But in the function code above I am NOT able to get the "ConfigurationManager" to read the node from Web.Config file. Please Help.
Also I have imported following libraries:
- Imports System.Data.SqlClient
-
Imports System.Configuration
-
Imports System.Web
Wow this sound familiar.
I did something very similar just a few months ago.
I wrote a class library in a project that managed all of my database manipulation. It was used within an asp.net project...and for security reasons I wanted to store the connection string in the web.config file.
What I ended up doing was passing the connection string to the class library functions from my asp.net project.
I don't think there is a way for both applications to access the connection strings node in the a web.config file.
(think about it ...would you want to allow any application access to this information? it could be malicious and destroy your database!)
I'll help you research the topic but I'm pretty sure that you can't do this.