Saturday, August 29, 2009

All Connection Strings Sample

You have the .NET Framework on your local computer and you want to connect to a Microsoft Access database called database1.mdb located in the following folder on your hard disk: c:\database1.mdb. Here are the parameters to create this connection string:

Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\database1.mdb;

OLE DB Provider for DB2 (from Microsoft)

For TCP/IP connections
oConn.Open = "Provider=DB2OLEDB;" & _
"Network Transport Library=TCPIP;" & _
"Network Address=xxx.xxx.xxx.xxx;" & _
"Initial Catalog=MyCatalog;" & _
"Package Collection=MyPackageCollection;" & _
"Default Schema=MySchema;" & _
"User ID=MyUsername;" & _
"Password=MyPassword"
For APPC connections

oConn.Open = "Provider=DB2OLEDB;" & _
"APPC Local LU Alias=MyLocalLUAlias;" & _
"APPC Remote LU Alias=MyRemoteLUAlias;" & _
"Initial Catalog=MyCatalog;" & _
"Package Collection=MyPackageCollection;" & _
"Default Schema=MySchema;" & _
"User ID=MyUsername;" & _
"Password=MyPassword"

ODBC Driver for Excel

oConn.Open "Driver={Microsoft Excel Driver (*.xls)};" & _
"DriverId=790;" & _
"Dbq=c:\somepath\mySpreadsheet.xls;" & _
"DefaultDir=c:\somepath"

ODBC Driver for MySQL (via MyODBC)
To connect to a local database (using MyODBC Driver)


oConn.Open "Driver={mySQL};" & _
"Server=MyServerName;" & _
"Option=16834;" & _
"Database=mydb"

To connect to a remote database


oConn.Open "Driver={mySQL};" & _
"Server=db1.database.com;" & _
"Port=3306;" & _
"Option=131072;" & _
"Stmt=;" & _
"Database=mydb;" & _
"Uid=myUsername;" & _
"Pwd=myPassword"

To connect to a local database (using MySQL ODBC 3.51 Driver)

oConn.Open "DRIVER={MySQL ODBC 3.51 Driver};" & _
"Server=myServerName;" & _
"Port=3306;" & _
"Option=16384;" & _
"Stmt=;" & _
"Database=mydatabaseName;" & _
"Uid=myUsername;" & _
"Pwd=myPassword"
Or
oConn.Open "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=myServerName;" & _
"DATABASE=myDatabaseName;" & _
"USER=myUsername;" & _
"PASSWORD=myPassword;"

Count online users in asp.net (VB)

Place the following code in Global.asax file. Here, we track the active Sessions for our web application. There are three subroutines into which we will be looking to do this – Application_OnStart, Session_OnStart, Session_OnEnd.

Step-1 :
In the Application_OnStart subroutine, we have to set the user count to 0, when the server starts the application.

Sub Application_OnStart (Sender as Object, E as EventArgs)
' Set user count to 0 when start the application
Application("ActiveUsers") = 0
End Sub

Step-2 :
In the Session_OnStart subroutine, we have to increament the Activeuser by 1:

Sub Session_OnStart (Sender as Object, E as EventArgs)
Application.Lock
Application("ActiveUsers") = Cint(Application("ActiveUsers")) + 1
Application.UnLock
End Sub
In this case you have to set Timeout – you don’t need to put anything here, but the default Timeout is 20 minutes, so you can change it depending on the needs of your particular application.

To set the session start time, we add (Session(”Start”) = Now). Basically, when the user hits the site and opens a web page (asp.net page), at the time of opening the page, the session starts. Next, we increase the active visitors count when we start the session (Application(”ActiveUsers”) = Cint(Application(”ActiveUsers”)) + 1 ). The Application lock & unlock adds more stability to the counting.

Step-3 :
we must decrement the number of Active Users on the basis of online sessions in the Session_OnEnd subroutine:

Sub Session_OnEnd(Sender as Object, E as EventArgs)
Application.Lock
Application("ActiveUsers") = Cint(Application("ActiveUsers")) - 1
Application.UnLock
End Sub

Step-4 :
Then you can place the following code to access the Application(”ActiveUsers”) in .aspx file

<%
Dim intNumber as Integer
intNumber =Application("ActiveUsers")
response.write (intNumber )
%> Currently Online