I cant get dns less connection to Ms Access db to work here the code.
In the dbconnection.asp file is this
Dim MM_IMT_STRING
''MM_IMT_STRING = "dsn=EDA;"
MM_IMT_STRING =("Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\inetpub\wwwroot\essel\Connections\EDA.mdb")
and in the default.asp is this
<!--#include file="Connections/dbconnection.asp" -->
Dim CHANNEL
Dim CHANNEL_numRows
Set CHANNEL = Server.CreateObject("ADODB.Recordset")
CHANNEL.ActiveConnection = MM_IMT_STRING
I have been struggling with this issue for days now, if someone know why its not linking up please tell me thanks.
Where is your Connection object created?
I'm missing something like
Set objConnMDB = Server.CreateObject("ADODB.Connection")
objConnMDB.ConnectionString = MM_IMT_STRING
objConnMDB.Open
CHANNEL.ActiveConnection = objConnMDB
' // do your stuff here '
objConnMDB.Close
Set objConnMDB = Nothing
Related
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've got various web apps (containing WCF services) in IIS under the default website. As long as they are all running in the same app pool they can access a shared isolated storage file no problem.
However, once I move them to different app pools I get "System.IO.IsolatedStorage.IsolatedStorageException: Unable to create mutex" when one tries to access a file created by another. They are all running under NetworkService user. I tried GetUserStoreForAssembly and GetMachineStoreForAssembly all with the same result. Any ideas why they couldn't use a shared file?
I made sure to close the stream and even dispose it in case one was holding onto it, but I am running a simple test where one service writes it, then another tries to read from it later, and it always fails.
Also, I am accessing the isolated store from a signed assembly.
Does anybody have any ideas?
Here is the code:
Private Sub LoadData()
Dim filename = FullFilePath(_fileName)
Dim isoStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()
' Tried GetMachineStoreForAssembly, same failure
isoStorage.CreateDirectory(ROOT_DIRECTORY)
If (isoStorage.GetFileNames(filename).Length = 0) Then
Return
End If
Dim stream As Stream = New IsolatedStorageFileStream(filename, FileMode.OpenOrCreate, isoStorage)
If stream IsNot Nothing Then
Try
Dim formatter As IFormatter = New BinaryFormatter()
Dim appData As Hashtable = DirectCast(formatter.Deserialize(stream), Hashtable)
Dim enumerator As IDictionaryEnumerator = appData.GetEnumerator()
While enumerator.MoveNext()
Me(enumerator.Key) = enumerator.Value
End While
Finally
stream.Close()
stream.Dispose()
stream = Nothing
End Try
End If
End Sub
Public Sub Save()
Dim filename = FullFilePath(_fileName)
' Open the stream from the IsolatedStorage.
Dim isoFile As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()
' Tried GetMachineStoreForAssembly, same failure
Dim stream As Stream = New IsolatedStorageFileStream(filename, FileMode.Create, isoFile)
If stream IsNot Nothing Then
Try
Dim formatter As IFormatter = New BinaryFormatter()
formatter.Serialize(stream, DirectCast(Me, Hashtable))
Finally
stream.Close()
stream.Dispose()
stream = Nothing
End Try
End If
End Sub
Looks like it was a trust issue.
After adding the assembly accessing the isolated storage file to the gac it magically worked as everything in the gac has full trust set automatically.
This works for me, but it might not always be an option to do this for other solutions. Check out the .NET Framework caspol utility if this is the case.
Hope this helps somebody! It was a huge pitafor me.
I want to simply retrieve a single record from a database in a classic ASP page. The code below basically works, but there are a couple problems I need help solving:
1) I want to see if a record was returned or not. result is not Nothing, so the redirect at the bottom is never performed. contact.RecordCount always returns -1, so I apparently can't use that either. Oddly, trying to access RecordCount outside the function throws an "Object doesn't support this property or method: 'RecordCount'" error.
2) I've read about disconnected queries and have seen examples where the connection and command are closed and/or set to Nothing at the end of the function. Is there a definitive best practice on what I should do?
3) Will using a parameterized query fully protect me from SQL injection, or do I need to manually remove dangerous words and characters?
function GetContactByUsername(username)
Dim conn, command, param, contact
set conn = server.CreateObject("adodb.connection")
conn.Open Application("DatabaseConnectionString")
Set command = Server.CreateObject("ADODB.COMMAND")
set command.ActiveConnection = conn
command.CommandType = adCmdText
command.CommandText = "Select * from MY_DATABASE.dbo.Contact where Username = ?"
Set param = command.CreateParameter ("Username", adVarWChar, adParamInput, 50)
param.value = username
command.Parameters.Append param
Set contact = Server.CreateObject("ADODB.RECORDSET")
contact.Open command
Response.Write contact.RecordCount '' always -1
set GetContactByPurlCode = contact
end function
dim result
result = GetContactByUsername(Request.QueryString("username"))
if result is Nothing then '' never true
Response.Redirect "/notfound.asp"
end if
FirstName = Trim(result("FirstName"))
LastName = Trim(result("LastName "))
1) To check for a lack of records, use rs.EOF, not "Is Nothing." The RecordSet object is always an object. It's just that sometimes it doesn't have any rows.
If you want to use RecordCount but are getting -1, then switch to a client-side cursor (adUseClient).
2) No definitive best-practice here, but I've personally always closed the Connection and Command, and have not had much in the way of performance problems. Connection objects are particularly precious, so close them as early as possible on high volume pages.
3) Yes, parameterizing your variable is perfect, unless you are calling a stored procedure that constructs a dynamic query.
By the way, you should avoid "SELECT *" as that will cause you to return more data than needed and is a maintenance problem waiting to happen.
Connection Code:
set conx = Server.CreateObject("ADODB.connection")
conx.Open Application("connectionString")
set cmdx = server.CreateObject("ADODB.command")
cmdx.ActiveConnection = conx
cmdx.CommandText = "dbo.sproc"
cmdx.CommandType = &H0004
set rsx = Server.CreateObject("ADODB.Recordset")
rsx.open cmdx
resarray = rsx.getrows
This connection string works:
connectionString = "DRIVER=SQL Server;UID=User;Address=000.000.000.000;Network=DBMSSOCN;DATABASE=Database;SERVER=server;Password=password;"
This doesn't...
connectionString = "Provider=SQLOLEDB;Data Source=000.000.000.000;UID=User;Address=000.000.000.000;Network=DBMSSOCN;DATABASE=Database;SERVER=server;Password=password;"
The error I get is:
ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
What am I missing?
Just a punt here, but the way OLEDB drivers handle Row count informationals differs from ODBC.
I very much suspect that if you add SET NOCOUNT ON at the top of the Stored Procedure the problem will go away.
Sounds like a permissions problem in the database!
I have transferred a Classic asp site running on windows server 2003 to windows server 2008 but suddenly the below code has stopped working.
Const connStr_FC08 = "Provider=SQLNCLI10;Server=DS-47500;Database=TestDB;Uid=TestLogin;Pwd=test;Network=dbmssocn;"
Function connDB(OpenDB)
DIM conn
SET conn = Server.CreateObject("ADODB.Connection")
conn.open = connStr_FC08
If OpenDB = "Y" Then conn.open
connDB = conn
End Function
dim cn, cmd
cn = connDB("Y")
response.Write(cn.state)
This returns the below error
Microsoft VBScript runtime error '800a01a8'
Object required: 'Provider=SQLNCLI10.1'
This happens on the below line
response.write(cn.state)
Thanks
Chris
I see a few possible syntax issues with the code you posted:
...
conn.open = connStr_FC08
...
connDB = conn
...
cn = connDB("Y")
Should it be updated to the following?
...
conn.ConnectionString = connStr_FC08
...
Set connDB = conn
...
Set cn = connDB("Y")
You have that SQL Provider installed right?
You can put that function into a simple VBScript script to test without altering your pages any.
If I take opening of the connection out of the function and put in inline then there is no error and it works.
But my whole site works by using this function so a) I dont want to have to rewrite my code and b) I dont understand why this does not work when it used to.