suu
04-26-2004, 03:43 PM
hello!
i've got a big problem that might be small for you.
you see, i'm trying to get values on my DB (using a query done on my page) and export them to an already existing temp excel file. the name of the file depends of the users sessionID.
i'm having a really big trouble writting the values on my DB
here's the code:
------------------------
<% Dim var_div,var_aux, ConnExcel, ConnBD, rsCA, rsaux
Dim SourceXLS, DestXLS, myBD, fso
var_sessionID=Session.SessionID
var_aux= "teste" & var_sessionID & ".xls"
SourceXLS = "\\sacavem07\pagepi\WEB\OUTRAS_DIV\REL_DIV_CA.xls"
DestXLS = "\\sacavem07\pagepi\WEB\OUTRAS_DIV" & "\" & var_aux
myBD = "\\sacavem07\pagepi\BD_PI.mdb"
response.write DestXLS
Set ConnExcel = Server.CreateObject("ADODB.Connection")
ConnExcel.open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DestXLS & ";" & _
"Extended Properties=""Excel 8.0;HDR=NO;"""
Set ConnBD = Server.CreateObject("ADODB.Connection")
Set rsCA = Server.CreateObject("ADODB.Recordset")
ConnBD.open "Provider=Microsoft.Jet.OLEDB.4.0; data source=" & myBD
SQLStmtCA = "SELECT Equip, Imob, Marca, Modelo, [Nº], Nome FROM TBL_COMP_U WHERE [Divisão]='CA'" &_
"UNION SELECT Equip, Imob, Marca, Modelo, [Nº], Nome FROM TBL_IMP_U WHERE [Divisão]='CA'" &_
"UNION SELECT Equip, Imob, Marca, Modelo, [Nº], Nome FROM TBL_MON_U WHERE [Divisão]='CA'" &_
"UNION SELECT Equip, Imob, Marca, Modelo, [Nº], Nome FROM TBL_SCAN_U WHERE [Divisão]='CA'"
rsCA.open SQLStmtCA, ConnBD, 3
response.write rsca("Equip")
'set rsaux = Server.CreateObject("ADODB.Recordset")
'SQLStmtaux = "SELECT * FROM " & var_aux
'With rsaux
'.ActiveConnection = ConnExcel
'.CursorLocation = adUseClient
'.CursorType = adOpenKeyset
'.LockType = adLockOptimistic
'.Source = SQLStmtaux
'.Open
'End With
'DO WHILE NOT(rsCA.EOF)
'rsaux.AddNew
'FOR i=0 to 6
' rsaux.Fields(i).Value = rsCA(i).Value
'NEXT
'rsaux.Update
'rsCA.MoveNext
'Loop
rsCA.Close
Set rsCA = Nothing
ConnBD.Close
Set ConnBD = Nothing
ConnExcel.Close
Set ConnExcel = Nothing
%>
------------------------------------
as you can see by the commented lines, i can't seem to be able to write on my excel file. it always gives the error:
Microsoft JET Database Engine error '80004005'
The Microsoft Jet database engine cannot open the file 'teste255344643'. It is already opened exclusively by another user, or you need permission to view its data.
-------------------------------------
perhaps i'm using the wrong method.
ideas on how to solve this or another way i might do this?
i'm really desperate here. i'm been trying to solve this for almost two weeks.
i've got a big problem that might be small for you.
you see, i'm trying to get values on my DB (using a query done on my page) and export them to an already existing temp excel file. the name of the file depends of the users sessionID.
i'm having a really big trouble writting the values on my DB
here's the code:
------------------------
<% Dim var_div,var_aux, ConnExcel, ConnBD, rsCA, rsaux
Dim SourceXLS, DestXLS, myBD, fso
var_sessionID=Session.SessionID
var_aux= "teste" & var_sessionID & ".xls"
SourceXLS = "\\sacavem07\pagepi\WEB\OUTRAS_DIV\REL_DIV_CA.xls"
DestXLS = "\\sacavem07\pagepi\WEB\OUTRAS_DIV" & "\" & var_aux
myBD = "\\sacavem07\pagepi\BD_PI.mdb"
response.write DestXLS
Set ConnExcel = Server.CreateObject("ADODB.Connection")
ConnExcel.open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DestXLS & ";" & _
"Extended Properties=""Excel 8.0;HDR=NO;"""
Set ConnBD = Server.CreateObject("ADODB.Connection")
Set rsCA = Server.CreateObject("ADODB.Recordset")
ConnBD.open "Provider=Microsoft.Jet.OLEDB.4.0; data source=" & myBD
SQLStmtCA = "SELECT Equip, Imob, Marca, Modelo, [Nº], Nome FROM TBL_COMP_U WHERE [Divisão]='CA'" &_
"UNION SELECT Equip, Imob, Marca, Modelo, [Nº], Nome FROM TBL_IMP_U WHERE [Divisão]='CA'" &_
"UNION SELECT Equip, Imob, Marca, Modelo, [Nº], Nome FROM TBL_MON_U WHERE [Divisão]='CA'" &_
"UNION SELECT Equip, Imob, Marca, Modelo, [Nº], Nome FROM TBL_SCAN_U WHERE [Divisão]='CA'"
rsCA.open SQLStmtCA, ConnBD, 3
response.write rsca("Equip")
'set rsaux = Server.CreateObject("ADODB.Recordset")
'SQLStmtaux = "SELECT * FROM " & var_aux
'With rsaux
'.ActiveConnection = ConnExcel
'.CursorLocation = adUseClient
'.CursorType = adOpenKeyset
'.LockType = adLockOptimistic
'.Source = SQLStmtaux
'.Open
'End With
'DO WHILE NOT(rsCA.EOF)
'rsaux.AddNew
'FOR i=0 to 6
' rsaux.Fields(i).Value = rsCA(i).Value
'NEXT
'rsaux.Update
'rsCA.MoveNext
'Loop
rsCA.Close
Set rsCA = Nothing
ConnBD.Close
Set ConnBD = Nothing
ConnExcel.Close
Set ConnExcel = Nothing
%>
------------------------------------
as you can see by the commented lines, i can't seem to be able to write on my excel file. it always gives the error:
Microsoft JET Database Engine error '80004005'
The Microsoft Jet database engine cannot open the file 'teste255344643'. It is already opened exclusively by another user, or you need permission to view its data.
-------------------------------------
perhaps i'm using the wrong method.
ideas on how to solve this or another way i might do this?
i'm really desperate here. i'm been trying to solve this for almost two weeks.