I have an old ASP site (written a long time ago by a former employee) that connects to a 2003 ODBC database using DSN. The servers have been updated by our hosts to 2008, and we can no longer use ODBC so I have to make the connections DSN-Less.
Unfortunately I have very little knowledge of ASP, and database connections through ASP. I wonder if anybody can help me change the code to connect to the Access database without ODBC?
I think it connects using this code:
<%
' Get current name of region and intro text
Dim objRec, sql, introtext
sql="SELECT * FROM hometext WHERE home_id = 1"
set objRec=Server.CreateObject("ADODB.Recordset")
objRec.Open sql, "dsn=databasename"
introtext = Replace(objRec("home_introtext"), vbCrLf, "<br />")
' Get the 5 newest news items
Dim objRec2, sql2, newstext
sql2="SELECT TOP 5 news_date, news_text FROM news ORDER BY news_date DESC"
set objRec2=Server.CreateObject("ADODB.Recordset")
objRec2.Open sql2, "dsn=databasename"
' Get all images to appear to page
Dim objRec3, sql3
sql3="SELECT * FROM homeimages ORDER BY homeimage_date DESC"
set objRec3=Server.CreateObject("ADODB.Recordset")
objRec3.Open sql3, "dsn=databasename"
' Get the next 5 events from the current date
Dim objRec4, sql4
sql4="SELECT TOP 5 event_date, event_name FROM events WHERE event_date >= " & niceDateAccess(Date()) & " ORDER BY event_date"
set objRec4=Server.CreateObject("ADODB.Recordset")
objRec4.Open sql4, "dsn=databasename"
%>
I'm not sure how it all connects, I'm not much of a scripter.
Any (dumbed down) help would be appreciated!
Thanks
EDIT: The database is sat in the 'private' folder in the root folder on the server.
Here is a sample code. Change your database name and tablefield name
set conob = Server.CreateObject("ADODB.Connection")
conob.Provider="Microsoft.Jet.OLEDB.4.0"
conob.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.MapPath("YourDatabaseName.mdb")
Set rsuni = Server.CreateObject("ADODB.Recordset")
sqlStr="select * from Student_Entry"
rsuni.open sqlStr,conob
You must give full access to your database by which user you are logged on.
Related
i try to fetch records from Apache Ignite inmemory database via Microsoft Access 2016 32-Bit and Apache Ignite 32-Bit ODBC-driver with default settings. OS is Windows 10.
Import as a linked table does not work so i tried via ADODB-Class.
Connection.Open and Recordset.Open works and i can see all columns (ID and NAME) of sample table CITY in the Recordset. But when i try to fetch the first record with MoveFirst or MoveNext, i get the error 'specified attribute is not supported'. I tried the same with CursorLocation=adUseClient and the error message changes to 'wrong parameter'. Default Provider is MSDASQL.1. Is this the correct Provider? Any idea how to fetch records with ADODB?
Code
`
Public Sub QueryIgnite()
Dim ADOrs As ADODB.Recordset
Dim ADOcon As ADODB.Connection
Set ADOcon = New ADODB.Connection
ADOcon.ConnectionString = "DSN=Apache-Ignite-DSN"
'ADOcon.CursorLocation = adUseClient
ADOcon.Open
Set ADOrs = New ADODB.Recordset
ADOrs.Open "select * from city", ADOcon, adOpenForwardOnly
ADOrs.MoveNext
Debug.Print ADOrs.Fields("NAME")
ADOrs.Close
ADOcon.Close
End Sub
`
Thank you in advance.
Regards.
Guido Clesius
A ticket on apache.org is created to fix the bug. See https://issues.apache.org/jira/browse/IGNITE-18210
We have a search page on our website that we made using ASP Classic on Windows Server 2003. Now we have migrated over to Windows Server 2012 and we need to make a new search page as the code will not work on Windows Server 2012 Search Service.
Has anyone come across this yet. I have been struggling trying to find good information on how to do this. If possible can someone show some coding examples on how this is done?
Thank you in advance.
<%
'Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Open "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"
Set adoCommand.ActiveConnection = adoConnection
strQuery = "SELECT Top 1000 System.ItemPathDisplay FROM SYSTEMINDEX"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 10
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
' Run the query.
Set adoRecordset = adoCommand.Execute
adoRecordset.MoveFirst
Do Until adoRecordset.EOF
response.write(adoRecordset.Fields.Item("System.ItemPathDisplay")& "<br />")
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close
%>
I have a bit of a problem and could really use some help. My organization recently migrated from Office 2007 to Office 2010. I had a database that I developed using Access 2007 (using the .accdb database file type). Throughout the migration process, I was still making updates to my database. All the updates were made via an Office 2007 machine and everything worked on the 2010 systems that I deployed it to, as well as the 2007 boxes. The problem now is that since all the computers are officially on 2010, I cannot seem to create an Accde file from Access 2010. The error I receive is: " The command or action 'MakeMDEFile' isn't available now." * You may be in a read-only database or an unconverted database from an earlier version..." The code is compiled with no errors and my references are good. I have tried to re-compile the code, re-name the wizards in the "C:\Program Files\Microsoft Office\Office14\ACCWIZ" folder and let them re-install, and import all my objects into a new database based on this article: http://msdn.microsoft.com/library/office/dn602608%28v=office.14%29.aspx; all to no avail.I do not have any web content or anything Access 2010 specific, as I only made adjustments to the things I created in 2007. I did read that Access must be compiled on the same version that it was created on, but I thought since both 2007 and 2010 use the .accdb file format it would be compatible? Any advice on this? Thank you.
Thank you for your quick answer! That worked great. I was able to successfully export my DB using the code and I also imported all the objects with the exception of the queries. (I was able to create the accde.) Because I have so many objects, I used a script to import everything. The problem I am experiencing now is with my SQL queries. The export script named the text files a little different for the SQL queries and I don't know how to handle them. Below is my code that worked for the rest of the objects:
Public Sub batchImport_queries()
On Error GoTo batchImport_Err
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String
strFolderPath = "C:\Users\Me\Desktop\dbexport\queries\"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
objF1.Name = Right(objF1.Name, Len(objF1.Name) - 6)'strips "Query_"
objF1.Name = Left(objF1.Name, Len(objF1.Name) - 3) 'strips ".txt"
Application.Application.LoadFromText acQuery, objF1.Name, strFolderPath & objF1.Name
Next
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
batchImport_Exit:
Exit Sub
batchImport_Err:
MsgBox Err.Number & " " & Err.Description
Resume batchImport_Exit
End Sub
That worked for queries like: "Query_qryAvailable.txt" but the SQL ones look like this: "Query_~sq_cCIPSSubform~sq_RosterSubform.txt". It seems to be encapsulating "~sq_c" around the first part of the query name and then the form/subform/or control that is associated with it at the last part of the filename...or I could be completely off. I can't figure out the pattern. Some of them have "~sq_f" instead, only at the leading part.(I'm guessing those are for forms?) Anyway, is there a better way to format the file name (if that's what has to be done) to remove those to my original query names and import correctly? Please let me know if that doesn't make sense. Thank you for your time.
It's possible to export an Access database to text files, see here: http://www.access-programmers.co.uk/forums/showthread.php?t=99179.
Option Compare Database
Option Explicit
Public Sub ExportDatabaseObjects()
On Error GoTo Err_ExportDatabaseObjects
Dim db As Database
'Dim db As DAO.Database
Dim td As TableDef
Dim d As Document
Dim c As Container
Dim i As Integer
Dim sExportLocation As String
Set db = CurrentDb()
sExportLocation = "C:\Temp\" 'Do not forget the closing back slash! ie: C:\Temp\
For Each td In db.TableDefs 'Tables
If Left(td.Name, 4) <> "MSys" Then
DoCmd.TransferText acExportDelim, , td.Name, sExportLocation & "Table_" & td.Name & ".txt", True
End If
Next td
Set c = db.Containers("Forms")
For Each d In c.Documents
Application.SaveAsText acForm, d.Name, sExportLocation & "Form_" & d.Name & ".txt"
Next d
Set c = db.Containers("Reports")
For Each d In c.Documents
Application.SaveAsText acReport, d.Name, sExportLocation & "Report_" & d.Name & ".txt"
Next d
Set c = db.Containers("Scripts")
For Each d In c.Documents
Application.SaveAsText acMacro, d.Name, sExportLocation & "Macro_" & d.Name & ".txt"
Next d
Set c = db.Containers("Modules")
For Each d In c.Documents
Application.SaveAsText acModule, d.Name, sExportLocation & "Module_" & d.Name & ".txt"
Next d
For i = 0 To db.QueryDefs.Count - 1
Application.SaveAsText acQuery, db.QueryDefs(i).Name, sExportLocation & "Query_" & db.QueryDefs(i).Name & ".txt"
Next i
Set db = Nothing
Set c = Nothing
MsgBox "All database objects have been exported as a text file to " & sExportLocation, vbInformation
Exit_ExportDatabaseObjects:
Exit Sub
Err_ExportDatabaseObjects:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_ExportDatabaseObjects
End Sub
If the principle still holds, you should be able to import the resulting objects to a fresh database. If there are any problems with permissions, that should become evident in the text files, but normally this strips all permissions.
I am a bit new to this web application stuff. When I create a new project in Visual Studios 2012 for ASP.NET Web Forms Application, it generates several predefined pages/functions. I actually want to use these functions since it seems to look like it might save me some time.
At this point I noticed how it has a Register.aspx and Login.aspx, which works fine. The Problem is that I have a database in Access 2007 with some tables. I want to know if it is possible to do one of the following and how:
1) keep the DefualtConnection database and query for the currently logged in username, to then use that usename to query my Access Database for the information based on that username.
2) Create my Own Register and Login using the Access Database. I wonder how do I keep track of the logged in user for this case and I also get an error when using the Create User Wizard
Please help, I need this information so that I can continue working on my final project. The Prof has no clue on how to do this, and I have been searching the web for and answer, however it seems like I may not be asking the right questions. Thanks in advance :)
*Edit
•What I mean by logged in user:
Picture https://dl.dropbox.com/u/22962879/Project_4_Registro_Est/Logged%20in%20user%20Project4.png
•DefaulConnection:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Project_4_Registro_Est-20130131171154;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Project_4_Registro_Est-20130131171154.mdf"
providerName="System.Data.SqlClient" />
•My Access Database
myConn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\cast\Documents\test.accdb")
My Solution:
It turns out that i can get the logged in users name by calling User.Identity.Name.
So I did the following:
'//The following code is an example of using the Logged/signed in username to then'
'//Query other Databases based on the user name:'
Dim myConn As System.Data.OleDb.OleDbConnection
Dim cmd As New System.Data.OleDb.OleDbCommand
Dim sqlstring As String
'//Connecting to My Database:'
myConn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\cast\Documents\test.accdb")
'//Query I wish to use to find all data based on User name:'
sqlstring = "Select FirstName, LastName, UserType FROM users WHERE Username = '" + User.Identity.Name + "'"
Try
'//Start by opening the connection'
myConn.Open()
'//I use str for now to store the results'
Dim str As String = ""
'//Set the command by adding the SQL string and Connection:'
cmd = New OleDb.OleDbCommand(sqlstring, myConn)
'//Create variable which contains results from Executed command:'
Dim oledbReader As OleDb.OleDbDataReader = cmd.ExecuteReader
'//Keep reading each row that contains the Queried Results:'
While oledbReader.Read
'//Store result to str. each item is a Column in the order I Queried'
str = str + (oledbReader.Item(0) & " " & oledbReader.Item(1) & " (" & oledbReader.Item(2)).ToString() & ")" + "\n"
End While
'//Show results on page's Label1:'
Label1.Text = str
'//Close everything'
oledbReader.Close()
cmd.Dispose()
myConn.Close()
Catch ex As Exception
'//show error message if could not connect'
MsgBox("Can not open connection! X_X")
End Try
This should be using SimpleMembership. So ask WebMatrix.WebData.WebSecurity.CurrentUserName. Also WebSecurity.IsAuthenticated would be good to look at.
I'm using a dynamic pass-through query in Access 2010 to retrieve one or more records from a back-end database. After much trial and error, I plagiarized enough of the right code to retrieve the appropriate records and assign them to unbound text-boxes on my datasheet form during an OnLoad event. The only problem remaining is in displaying multiple records. I've verified that I AM retrieving multiple records, but the contents of each record's fields overwrite the previous values stored to the form's textbox controls, so I always end up with just a single record displayed in my datasheet when I expect to see anywhere from one to 10.
I'm sure it's a simple solution. Can someone please point it out to me?
Private Sub Form_Load()
Dim sqlString As String
sqlString = "SELECT Transmitter_ID, Receiver_ID, UTC_Date, Local_Date from Detections"
If Not IsNull(Me.OpenArgs) Then
sqlString = sqlString & " where " & OpenArgs
End If
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As ADODB.Recordset
'Define and open connection
cnn.ConnectionString = "DRIVER={SQLite3 ODBC Driver};Database=z:\EWAMP\EWAMP_be_dev.sqlite"
cnn.Open
'Define ADO command
cmd.ActiveConnection = cnn
cmd.CommandText = sqlString
'Populate and enumerate through recordset
Set rst = cmd.Execute
If rst.EOF Then
MsgBox "Nothing found...", vbInformation + vbOKOnly
Exit Sub
Else
Do While Not rst.EOF
'// I'm guessing the problem is with my control assignments, here.
Me.cntl_Receiver_ID.Value = rst("Receiver_ID")
Me.cntl_Transmitter_ID.Value = rst("Transmitter_ID")
Me.cntl_UTC_Date.Value = rst("UTC_Date")
Me.cntl_Local_Date.Value = rst("Local_Date")
Debug.Print {Show me the four control values}
rst.MoveNext
Loop
End If
End Sub
Cheers!
DUHdley
I don't believe a form in Datasheet view can be used as an unbound form. But you can use the ADO recordset as the forms recordset.
Set Me.Recordset = rst
Then just be careful not to close your variable named rst until the form closes.
Another alternative solution is to use an in-memory, fabricated, disconnected ADO recordset. Basically, you'd end up creating a new recordset, append fields to it to match your existing recordset, and then move all the data into your new recordset. But I really don't see the point in doing this if you already have a valid, filled ADO recordset.
If you really need/want to display multiple records in an unbound form, I think you would have to use ActiveX controls such as the GridView, ListView, TreeView, or MSFlexGrid. I've noticed that most skilled, professional Access developers stay away from ActiveX controls as much as possible. If and when they do use them, they usually limit it to only the TreeView and the ListView, I think because they are about the only ActiveX controls that add enough value to be worth putting up with whatever problems they might introduce.
I suggest you take a look at this article concerning the differences between DAO and ADO.
http://www.utteraccess.com/wiki/index.php/Choosing_between_DAO_and_ADO
A reader in another forum pointed me to a solution similar to that posed by HK1, namely Set Me.Recordset = rst. That fixed my original problem, but created another.
First I re-bound my four textbox controls on the unbound form, and then modified the code significantly, using the sample from http://msdn.microsoft.com/en-us/library/ff835419.aspx. The revised code looks like this:
Private Sub Form_Load()
Dim sqlString As String
sqlString = "SELECT Transmitter_ID, Receiver_ID, UTC_Date, Local_Date from Detections"
If Not IsNull(Me.OpenArgs) Then
sqlString = sqlString & " where " & OpenArgs
End If
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
'Define and open connection
Set cn = New ADODB.Connection
cn.ConnectionString = "DRIVER={SQLite3 ODBC Driver};Database=z:\EWAMP\EWAMP_be_dev.sqlite;"
cn.Open
'Create an instance of the ADO Recordset class,
'and set its properties
Set rs = New ADODB.Recordset
With rs
Set .ActiveConnection = cn
.Source = sqlString
'// .LockType = adLockOptimistic
.LockType = adLockReadOnly
.CursorType = adOpenKeyset
'// .CursorType = adOpenStatic
.Open
End With
'Set the form's Recordset property to the ADO recordset
Set Me.Recordset = rs
Set cn = Nothing
Set rs = Nothing
End Sub
The form now display four rows for four returned records, 20 rows for twenty records, and on, up to at least 256k rows (as specified by my parameter set). The only remaining teeny tiny problem is that for four or more records, if I press the "last row" navigation button (>|), the local cursor sets focus to one or more of the intermediate rows, and the control's properties sheet refreshes vigorously (multiple times per second). If I have more form rows than can be displayed on the screen, I can not navigate or cursor to the last row. It's as though the record set is constantly being updated.
As you can see, I've played with the RecordSet LockType and CursorType properties (including adOpenDynamic and adOpenForwardOnly, both of which caused a run-time error with the Set Me.Recordset statement). Toggling the LockType between adLockOptimistic and AdLockReadOnly, and the CursorType between adOpenKeyset and adOpenStatic makes no difference in the retrieval performance (which is fantastically fast now!) or the apparent refresh rate (which is even faster, unfortunately).
Perhaps it's worth mentioning that the "Detections" table the sqlString "selects" from contains ~4M records. I was frustrated in my previous attempts to use a form with a data source bound to a passthrough query of this table, because the query always returned the entire 4M records to the client regardless of the filter/WhereClause/OpenArgs parameter I passed to the form. The solution shown above would be perfect if only I could close the connection (I've tried) or otherwise quiesce the RecordSet after I've invoked it once.