J
Jerry
I'm trying to execute a stored procedure in a loop while paging through
database table records but the stored procedure isn't running. I get
the folowing error: The component 'adodb.connection' cannot be created.
Apartment threaded components can only be created on pages with an <%@
Page aspcompat=true %> page directive.
Can anyone tell me what I'm doing wrong? Below is my code.
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'Create a connection string
Dim connString As String
Dim strID As String
Dim strSP As String
connString = "Provider=SQLOLEDB;Data Source=OET-JBEACH;Initial
Catalog=TEST;User Id=test;Password=test;"
'Open a connection
Dim objConnection As OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()
Dim strSQL As String = "SELECT Blob_ID, Blob_Date FROM
dbo.tblBlob WHERE Blob_PhotoYesNo=33 ORDER BY Blob_Date desc"
'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)
'run stored procedure for each record in the table
While objDataReader.Read()
'set file name
strID = objDataReader("Blob_ID") & "_" &
Right(objDataReader("Blob_Date"), 4) & ".jpg"
'set stored procedure execute line
strSP = "ntext2file, 'c:\blob\" & strID & "', 'tblBlob',
'Blob_Photo', 'where Blob_ID=" & objDataReader("Blob_ID") & "'"
' ***** the response.write part works. the rest doesn't
Response.Write(strSP & "<br>")
Dim c
c = Server.CreateObject("adodb.connection")
c.Open(Application("connString"))
c.Execute(strSP)
c.Close()
c = Nothing
End While
'Close the datareader/db connection
objDataReader.Close()
End Sub
</script>
database table records but the stored procedure isn't running. I get
the folowing error: The component 'adodb.connection' cannot be created.
Apartment threaded components can only be created on pages with an <%@
Page aspcompat=true %> page directive.
Can anyone tell me what I'm doing wrong? Below is my code.
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'Create a connection string
Dim connString As String
Dim strID As String
Dim strSP As String
connString = "Provider=SQLOLEDB;Data Source=OET-JBEACH;Initial
Catalog=TEST;User Id=test;Password=test;"
'Open a connection
Dim objConnection As OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()
Dim strSQL As String = "SELECT Blob_ID, Blob_Date FROM
dbo.tblBlob WHERE Blob_PhotoYesNo=33 ORDER BY Blob_Date desc"
'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)
'run stored procedure for each record in the table
While objDataReader.Read()
'set file name
strID = objDataReader("Blob_ID") & "_" &
Right(objDataReader("Blob_Date"), 4) & ".jpg"
'set stored procedure execute line
strSP = "ntext2file, 'c:\blob\" & strID & "', 'tblBlob',
'Blob_Photo', 'where Blob_ID=" & objDataReader("Blob_ID") & "'"
' ***** the response.write part works. the rest doesn't
Response.Write(strSP & "<br>")
Dim c
c = Server.CreateObject("adodb.connection")
c.Open(Application("connString"))
c.Execute(strSP)
c.Close()
c = Nothing
End While
'Close the datareader/db connection
objDataReader.Close()
End Sub
</script>