Forum Moderators: open
---testconnect.aspx---
<%@ Page Language="vb" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %><html>
<head>
<title>Database Connection Test</title>
<script runat="server">
sub Page_Load(sender as Object, e as EventArgs)
varlabel.text = Session("var")'Create a connection string
Dim connString as String
connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\sites\portfolio\portfoliodb.mdb;"
'Open a connection
Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()
'Specify the SQL string
Dim strSQL as String = "SELECT * FROM test"
'Create a command object
Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)'Get a datareader
Dim objDataReader as OleDbDataReader
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)'Do the DataBinding
dgResults.DataSource = objDataReader
dgResults.DataBind()
'Close the datareader/db connection
objDataReader.Close()
end sub
</script>
</head>
<body><!--<asp:DataGrid id="dgResults" runat="server" />-->
<br><br>
<asp:Label ID="varlabel" Runat="server" /></body>
</html>
---Global.asa
Dim ConnectionString As String -- This is at the top of the Gloal.asa in the public class just below the inherits
-- This is in the SessionStart part of the global.asa
ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\sites\portfolio\portfoliodb.mdb;"
Additional: The forum is adding the http:// before the wwwroot. It is not in my code.
Or simply paste the whole string into every page.
G.