CodeWidgets.com Online Source Code Library -ASP, ASP.NET, VB, VB.Net,
Microsoft® Access, Javascript, VBScript, Website Design, Web Applications,
Custom Programming Services Available.
|
|
ASP, ASP.NET, VB, VB.Net,
Microsoft® Access, Javascript, VBScript,
Website Design, Web Applications |
|
|
Shopping Cart
(0) Items $0.00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Website Stats to Date
|
|
Pages Viewed 4,401,732
|
|
Visitors
1,206,536
|
|
Widgets Viewed
3,009,755
|
| Since January 1/2003 |
| |
Active Users: 18
|
|
|
|
|
|
 |
|
|
| |
| Widget
#CS0042 |
Create a Session Database Connection through code (ASP.NET)Create a Session Database Connection through code (ASP.NET) |
|
|
|
|
|
| Widget Info
|
VB.NET / ASP.NET
the source code below will connect to an Access Database, to change to SQL
Server make the appropriate changes to the Connection String |
|
| Create a an xml file named datasource.xml, and save
it to the bin directory of your web application |
| Use the following XML as a template |
| Substitute your application
name and database file name below |
<DataSource>
<Path>C:\Inetpub\wwwroot\appname\databasename.mdb</Path>
</DataSource> |
| Make the following changes to your Global.asax.vb
file |
Sub Session_Start(ByVal
sender As Object, ByVal e As EventArgs)
' Fires when the session is started
Session("DBCon") = DBCon()
End Sub |
|
Function DBCon() As
System.Data.OleDb.OleDbConnection
Try
'Load datasource path from XML File
Dim xml As New System.Xml.XmlDocument()
xml.Load(Server.MapPath(".") & "\bin\datasource.xml")
'Pass value to Connection Path
Dim Path As String = xml.SelectSingleNode("/DataSource/Path[1]").InnerText()
'Build Connection String
Dim strConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Password='';User ID=Admin;Data
Source=" & Path & ";Mode=Share Deny None"
'Open Database
DBCon = New System.Data.OleDb.OleDbConnection(strConnectionString)
DBCon.Open()
Catch
End Try
End Function |
Function CloseDBCon(ByVal
m_DBCon As System.Data.OleDb.OleDbConnection) As Boolean
m_DBCon.Close()
End Function |
| To use the Connection in a web form's code behind
file |
| Dim DBCon as new
System.Data.OleDb.OleDbConnection() |
| DBCon = Session("DBCon") |
| WARNING: If at anytime you close the connection to
your database it must be re-opened before it can be used |
|
|
|
| Licensing |
| Format:
HTML Article |
| Online Document |
| Licencing Terms:
Reserved Copyright |
Copyright 2002 CodeWidgets.com
Reproduction or duplication of this article without the authors permission is prohibited and protected under the copyright laws of Canada.
This source code is provided to you "as is" without warranty
CLICK HERE FOR TERMS OF USE
Copyright 2002-2006 Comrie Software Solutions |
|
| Related Widgets |
|
|
| ShoppingCart Empty |
|
|
|
| Featured Widgets |
| WebStore |
| Online Store Application
Template (ASP.NET) |
| More... |
|
| ShoppingCart |
| WebUserControl (ASP.NET) |
| More... |
|
| Calendar Reports |
| (Monthly View) |
| For Microsoft® Access |
| More... |
|
Online Voting/Survey
Web-App |
 |
|
More... |
|
|
|
|
|
 .. this is one site that believes in Customer Service. I had questions, I had answers quickly. No "wait for days", No "buy this and
find out". Just courteous and HELPFUL answers.
It is refreshing to find a site that really cares about their products and
stands behind them!
And their products perform as they promote them. John L. |
 When I received my ASP.NET E-Commerce application it was for the purpose of marketing my software inventory via the internet. It took a minimal amount of time to launch it and offers host of traffic tracking options for further market study and analysis. Overall an excellent product.
Richard G.
|
|
|
|
|
|
|
|
|