Connect to a specific lotus notes database/documen via vba - vba

I can connect to lotus notes via the following code. So basically I connect to the database: CLASTNAME/O=TEST/C=US.nsf
Set oSession = CreateObject("Notes.NotesSession")
Server = oSession.GetEnvironmentString("MailServer", True)
UserName = oSession.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set db = oSession.GETDATABASE("", MailDbName)
Set view = db.GetView("Customers") //ERROR
However, I want to connect to a specific database, which I have. Here is the document link:
<NDL>
<REPLICA C1451C8A:00575D55>
<VIEW OD3B89A25B:7D1FR7SA-OM4923732F:011L111C>
<NOTE OFAAAA64WE:GH1Q0W0W-IUZ0987MNB:2222F4LÖ>
<HINT>CN=ZZZUSDMS09/O=ZZZ/C=US</HINT>
<REM>Database 'UserName', View 'Customers', Document 'AG: A list of all company customers, Jannuary 9, 2009'</REM>
</NDL>
This is what I tried:
Sub notesBB()
'Const DATABASE = ""
Dim r As Integer
Dim i As Integer
Dim db As Object
Dim view As Object
Dim Entry As Object
Dim nav As Object
Dim oSession As Object 'The notes session
Dim nam As Object ' notes username
Dim v() As Variant ' to hold the subtotal values
Dim bills(12, 16) ' 12 months, 16 departments
r = 1
Worksheets(1).Range("A1:Z99").Clear
'##############################
'Start a session to notes
Set oSession = CreateObject("Notes.NotesSession")
Server = oSession.GetEnvironmentString("MailServer", True)
UserName = "CN=ZZZUSDMS09/O=ZZZ/C=US" 'oSession.UserName
CustomerDbName = "CZZZUSDMS09/O=ZZZ/C=US" & ".nsf"
'Open the mail database in notes
Set db = oSession.GETDATABASE("", CustomerDbName)
Set view = db.GetView("OD3B89A25B:7D1FR7SA-OM4923732F:011L111C")
view.AutoUpdate = True // here I get an error
Set nav = view.CreateViewNav
Set Entry = nav.GetFirst
Do Until Entry Is Nothing
If Entry.isCategory Then
r = r + 1
v = Entry.ColumnValues
For i = 1 To 16
bills(v(0), i) = v(4 + i)
Cells(4 + r, 2 + i) = bills(v(0), i)
Next
End If
Set Entry = nav.getNextCategory(Entry)
DoEvents
Loop
End Sub
However, as you can see I get an error hee: view.AutoUpdate = True // here I get an error
How to connect to this database via vba?
I really appreciate your answer!

Well, this doesn't look right:
CustomerDbName = "CZZZUSDMS09/O=ZZZ/C=US" & ".nsf"
'Open the mail database in notes
Set db = oSession.GETDATABASE("", CustomerDbName)
You're just appending ".nsf" to the user's fully disntinguished name in canonical form, and that would be an extremely unusual naming convention for databases on a server. Also, earlier in your code you retrieved the server name, but here you're specifying "" for the server name instead of using what you had retrieved, so the result is that the code will try to open the database on the local machine.
The NDL file is giving you the ReplicaID of the database here:
<REPLICA C1451C8A:00575D55>
You can use the OpenByReplicalID method instead:
repID = "C1451C8A00575D55" ' note that the : is removed
'Open the database by replica id
set db = new NotesDatabase("","")
If db.OpenByReplicaID( , "85255FA900747B84" ) Then
Print( db.Title & " was successfully opened" )
Else
Print( "Unable to open database" )
End If
The next problem, though, is that the NDL file is giving the view's UNID, not its name
<VIEW OD3B89A25B:7D1FR7SA-OM4923732F:011L111C>
There is no call in the Notes COM API that can retrieve a view by its UNID; you need the name for that. But do you really need to get the view? The NDL gives you the UNID of the document, here:
<NOTE OFAAAA64WE:GH1Q0W0W-IUZ0987MNB:2222F4LÖ>
So if your goal is to just get the specific document specified in the NDL, you can use a call to GetDocumentByUNID. Note, however that the actual UNID consists of only the 17 chars to the right of OF in the above tag, minus the : char. So your code would look like this:
unid = "AAAA64WEGH1Q0W0W" ' see note below!!
Set doc = db.GetDocumentByUnid(unid)
BTW, that UNID does not look legal. The chars should be hex, and the W, Q, and G are not. I'm going on the assumption that you (or someone) deliberately obfuscated the data in your NDL file.
If you do need to access the view, the NotesNoteCollection class may provide a way to get there, but it will not be trivial.
Finally, you may find this code from Stepehn Wissel helpful.

Specify the name of the view instead:
Set view = db.GetView("Customer")

Nice to see my code getting recycled ! it seems to me that you aren't using the correct database and view names. Are they not
Database 'UserName', and View 'Customers' ? (from your link). Whatever - when your XL VBA crashes out, in the Debug - Locals window, look for the object(s) that you have tried to instantiate with the SET command. If they show up as "nothing", you've got the SET command(s) wrong and trying to use the failed object (view) then crashes on the following line.
If your servername is "Yoda" I'd guess you need
Set db = session.getdatabase("Yoda", "Username.nsf")
Set view = db.GetView("Customers")

Related

powerdesigner vb/vba how to set default table mapping for excel source 2 target extract

I'm working on a script to extract source to target data from powerdesigner 16. I have a table that is sourced from multiple mappings in powerdesigner MAPPING_1, MAPPING_2, ETC. I can't figure out how to set the default mapping with vba code. I'm currently access the mappings with the code below. It will access the default mapping that was active when I last saved my data model. If anyone has insight on how to do this I would be very greatful.
Thanks
'
' get the table
' Dim mytable, col, cm
mytable = 'CUSTOMER_STAGING'
Dim obj As PdCommon.IdentifiedObject
Set obj = baseModel.FindChildByCode(mytable, cls_Table)
For Each col In obj.Columns
For Each cm In col.Mappings
Next
next
Not exactly the same objects, as I started playing with Conceptual Models. Two sources, and one target, all with entities named Entity_1, Entity_2, with the mappings set as excepted by the wizard.
Not exactly the same code, as I started playing with VBScript...
But it seems I was able to change the default mapping, just by setting the DefaultMapping attribute:
option explicit
dim myname
myname = "ENTITY_1"
Dim obj : Set obj = ActiveModel.FindChildByCode(myname, cls_Entity)
output "default: " & obj.defaultmapping
dim cm,changed
changed = false
For Each cm In obj.Mappings
output cm
if cm <> obj.defaultmapping and not changed then
output "set to " & cm
changed = true
set obj.defaultmapping=cm
end if
Next
output "default: " & obj.defaultmapping

OTA - ALM 11.52 - Building Graphs through OTA

I am trying to create reports in the 'Analysis View' using OTA and HP ALM 11.52.
I've searched the OTA Reference Documentation and looked for samples online and I've found a few samples, but none seem to work.
There seem to be three methods utilised:
TDConnection.GraphBuilder.BuildGraph(GraphDefinition)
TDConnection.testFactory.BuildSummaryGraph("TS_STATUS", "TS_STATUS", "", 0, myFilter, False, False)
and a third method involving an AnalysisItemFactory object that I can't find anywhere in the OTA documentation.
I've tried the first two and they seem to run without triggering an error, however, no graph appears in ALM.
Is there a difference between these methods and which is the cleanest method?
Here are my attempts so far:
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Method 1: GraphBuilder
'Set GB = QCConnection.GraphBuilder
'Set G1 = GB.CreateGraphDefinition(2, 0)
'G1.Property(0) = "TS_NAME"
'G1.Property(1) = "TC_STATUS"
'Set tsf = QCConnection.TestSetFactory
'Set myFilter = tsf.Filter
'myFilter.Filter ("TC_STATUS") = "Not(N/A)"
'G1.Filter = "Filter: Status[Not N/A]"
'Set g = GB.BuildGraph(G1)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Method 2: BuildSummaryGraph
'Dim testF
'Dim graph1
'Dim Filter
'Set testF = QCConnection.testFactory
'Set myFilter = testF.Filter
'myFilter.Filter("TS_STATUS") = "Not(N/A)"
'Set graph1 = _
'testF.BuildSummaryGraph("TC_NAME", "TS_STATUS", "", 0, myFilter, False, False)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Method 3: AnalysisItemsFactory? I can't find any documentation on this object, yet I've seen it referenced in other code samples.
'Set aiFolderFact = QCConnection.AnalysisItemFolderFactory
'Set aiFact = QCConnection.AnalysisItemFactory ~~~ This line actually runs fine so I know it at least exists. But I am definitely not using the proper methods below.
'Set G1 = aiFact.AddItem("")
'G1.Field("AI_PARENT_ID") = 1001 'Public
'G1.Field("AI_TYPE") = "Graph"
'G1.Field("AI_SUB_TYPE") = "Progress Graph"
'G1.Field("AI_OWNER") = qcUserName.Value
'G1.Field("AI_MODULE") = "requirement"
'G1.Field("AI_NAME") = "test graph"
'G1.Post
As I mentioned previously, all of these scripts run error free, but I see no graph in the Analysis View. I've also noticed that there seem to be no "Name" or "Path" fields.
I've taken a look at the tables, and there seems to be 'Analysis_Item_Folder' and 'Analysis Items' tables so It's know it's possible to do this through the OTA client. Is there an AnalysisItemFactory and could someone please kindly provide a sample script of what I'm looking for?
I was able to generate a report with the help of this HP ALM forum entry.
As in the forum mentioned it is not an official documented feature of HP ALM. Therefore it can be that in the future it won't work without replacement. Please keep that in mind.
In case the forum entry may get deleted I copied the answer by a user called "delarosa62" here (date of copy 2015/9/8):
Hi MichaelMotes and the rest of the community members.
I developed a VBA code to generate dashboard standard reports automatically. I get the "successful exception" you have mentioned. However my report does not get generated in my hard disk.
I don't get any errors.
I have adapted your Visial Basic Code to VBA using OTA. I have the otareport 1.0 Type Library and otaxml type lib registered in the tools/reference option in the VBA module window.
I am pasting my code below hoping you guys can give me some insight on this. I am not getting any errors. Just the exception which includes a successful completion message.
Sub externalSTDReports()
Dim reqFact
Dim reqFilter
Dim reqList
Dim gTDConn As Object
Set gTDConn = CreateObject("TDApiOle80.TDConnection")
'QC Connection data
login_id = ActiveWorkbook.Sheets("CONFIG").Cells(9, 3).value
login_passwd = ActiveWorkbook.Sheets("CONFIG").Cells(10, 3).value
domain_name = ActiveWorkbook.Sheets("CONFIG").Cells(11, 3).value
project_name = ActiveWorkbook.Sheets("CONFIG").Cells(12, 3).value
server_name = ActiveWorkbook.Sheets("CONFIG").Cells(13, 3).value
gTDConn.InitConnectionEx server_name
gTDConn.login login_id, login_passwd
gTDConn.Connect domain_name, project_name
Set Rep = New OTAREPORTLib.Reporter
Call Rep.SetConnection(gTDConn, 0) ' This line doesn´t return errors. But I don´t know if it is correct
Set RepConf = Rep.ReportConfig
Rep.File = "C:\Users\cris\AppData\Local\Temp\TD_80\4c223b57\Reports\std.html"
Rep.Template = "C:\Users\cris\AppData\Local\Temp\TD_80\4c223b57\Reports\default.xsl"
'******************************************************** filter Reports
Set aiFact = gTDConn.AnalysisItemFolderFactory
Set reportFact = gTDConn.AnalysisItemFactory
Set aiFilter = aiFact.Filter
Set aiList = aiFilter.NewList
Set anf = reportFact.Filter
Dim FilterStr As String
For Each ai In anf.NewList
reportName = ai.Name
reportID = ai.id
If reportName = "tmp" Then
FilterStr = ai.Field("AI_FILTER_DATA")
RepConf.Filter = FilterStr
On Error Resume Next
'i is empty. Don´t know why
i = Rep.Generate(0, 0) MsgBox i & " --- " & Rep.File Debug.Print Rep.File '-------------------- Exit For
End If
Next
Set gTDConn = Nothing
Set aiFact = Nothing
Set reportFact = Nothing
Set aiFilter = Nothing
Set aiList = Nothing Set anf = Nothing
Set RepConfig = Nothing
Set Rep = Nothing
MsgBox "END "
End Sub 'Pls HELP!!
Graphs can be generated under analysis folder, its a bit of a process because you need a sound understanding of the database, XML and OTA API. There is no direct API available for building graphs, I have created the code samples below
https://github.com/sumeet-kushwah/ALM_OTA_Wrapper/blob/master/ALM_Wrapper/Analysis.cs
Check the following functions
CreateDefectAgeGraph
CreateExcelReport
CreateDefectSummaryGraph
CreateSummaryGraph
These functions are called from the tests available below
https://github.com/sumeet-kushwah/ALM_OTA_Wrapper/blob/master/ALM_Wrapper_Tests/ALM_Wrapper_Test.cs
Look for test function
Test_AnalysisAndDashboardScripts
If you have any questions regarding the process, please let me know.

Add new network location, not map network drive

Let's say I have 100 users and I need to add several network locations for each user. They cannot be network drives (e.g. Q:) as some users already have more than 26 drives mapped.
I was hoping to do this using either a batch file or a VB script. I've managed to get it working using a VB script by adding network shortcuts but this isn't the solution the users need.
I've been searching and can't find anything related specifically to Network Locations.
I'm open to trying other methods.
EDITED to properly answer the question; the original answer, that creates a shortcut in Network Locations, is kept at the end.
After some testing, a network location is a read-only folder located in the %AppData%\Microsoft\Windows\Network Shortcuts folder, with two files inside: desktop.ini with a precise content (see in code) and a target.lnk shortcut to the target.
Option Explicit
Function CreateNetworkLocation( networkLocationName, networkLocationTarget )
Const ssfNETHOOD = &H13&
Const fsATTRIBUTES_READONLY = 1
Const fsATTRIBUTES_HIDDEN = 2
Const fsATTRIBUTES_SYSTEM = 4
CreateNetworkLocation = False
' Instantiate needed components
Dim fso, shell, shellApplication
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set shell = WScript.CreateObject("WScript.Shell")
Set shellApplication = WScript.CreateObject("Shell.Application")
' Locate where NetworkLocations are stored
Dim nethoodFolderPath, networkLocationFolder, networkLocationFolderPath
nethoodFolderPath = shellApplication.Namespace( ssfNETHOOD ).Self.Path
' Create the folder for our NetworkLocation and set its attributes
networkLocationFolderPath = fso.BuildPath( nethoodFolderPath, networkLocationName )
If fso.FolderExists( networkLocationFolderPath ) Then
Exit Function
End If
Set networkLocationFolder = fso.CreateFolder( networkLocationFolderPath )
networkLocationFolder.Attributes = fsATTRIBUTES_READONLY
' Write the desktop.ini inside our NetworkLocation folder and change its attributes
Dim desktopINIFilePath
desktopINIFilePath = fso.BuildPath( networkLocationFolderPath, "desktop.ini" )
With fso.CreateTextFile(desktopINIFilePath)
.Write "[.ShellClassInfo]" & vbCrlf & _
"CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}" & vbCrlf & _
"Flags=2" & vbCrlf
.Close
End With
With fso.GetFile( desktopINIFilePath )
.Attributes = fsATTRIBUTES_HIDDEN + fsATTRIBUTES_SYSTEM
End With
' Create the shortcut to the target of our NetworkLocation
Dim targetLink
targetLink = fso.BuildPath( networkLocationFolderPath, "target.lnk" )
With shell.CreateShortcut( targetLink )
.TargetPath = networkLocationTarget
.Save
End With
' Done
CreateNetworkLocation = True
End Function
CreateNetworkLocation "Tests", "\\192.168.1.2\c$"
Tested in Windows 7.
Original answer - Just in case someone finds it useful.
All you need to do is to create a shortcut in the folder:
%AppData%\Microsoft\Windows\Network Shortcuts
Just a VBScript sample (as indicated in the question, not sure if the tags points to another needs):
Option Explicit
Const ssfNETHOOD = &H13&
Dim fso, shell, shellApplication
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set shell = WScript.CreateObject("WSCript.Shell")
Set shellApplication = WScript.CreateObject("Shell.Application")
Dim networkLocationsFolder
networkLocationsFolder = shellApplication.Namespace( ssfNETHOOD ).Self.Path
With shell.CreateShortcut(fso.BuildPath( networkLocationsFolder, "Test PC.lnk" ))
.TargetPath = "\\192.168.1.10\c$"
.WindowStyle = 1
.IconLocation = "shell32.dll, 9"
.Description = "Access to Test computer drive"
.WorkingDirectory = "\\192.168.1.10\c$"
.Save
End With

Too few parameters in OpenRecordset code

I have two sets of code, that are the same I just change variables to another set that exist and now with the ones I changed I get an error saying "Run-time error '3061': Too few parameters. Expected 6."
This is the changed code:
Dim rec As Recordset
Dim db As Database
Dim X As Variant
Set db = CurrentDb
Set rec = db.OpenRecordset("UnitMoreInfoQ")
Const msgTitle As String = "Open Explorer"
Const cExplorerPath As String = "C:\WINDOWS\EXPLORER.EXE"
Const cExplorerSwitches As String = " /n,/e"
cFilePath = rec("ProjFilePath")
It highlights this line:
Set rec = db.OpenRecordset("UnitMoreInfoQ")
This is the first code:
Dim rec As Recordset
Dim db As Database
Dim X As Variant
Set db = CurrentDb
Set rec = db.OpenRecordset("ProjectMoreInfoQ")
Const msgTitle As String = "Open Explorer"
Const cExplorerPath As String = "C:\WINDOWS\EXPLORER.EXE"
Const cExplorerSwitches As String = " /n,/e"
cFilePath = rec("ProjFilePath")
As you can see, the line has the same amount of parameters:
Set rec = db.OpenRecordset("ProjectMoreInfoQ")
This has gotten me quite confused for awhile because of this. How do I fix this error?
I didn't get the same result as you when testing your db, and I still don't understand the difference. However, maybe we can still get you something which works in spite of my confusion.
The query contains 6 references to form controls, such as [Forms]![WorkOrderDatabaseF]![Text71]. Although you're certain that form is open in Form View when you hit the "too few parameters" error at db.OpenRecordset("UnitMoreInfoQ"), Access doesn't retrieve the values and expects you to supply them.
So revise the code to supply those parameter values.
Dim rec As DAO.Recordset
Dim db As DAO.database
Dim prm As DAO.Parameter
Dim qdf As DAO.QueryDef
Dim X As Variant
Set db = CurrentDb
'Set rec = db.OpenRecordset("UnitMoreInfoQ")
Set qdf = db.QueryDefs("UnitMoreInfoQ")
For Each prm In qdf.Parameters
prm.value = Eval(prm.Name)
Next
Set rec = qdf.OpenRecordset(dbOpenDynaset) ' adjust options as needed
I'm leaving the remainder of this original answer below in case it may be useful for anyone else trying to work through a similar problem. But my best guess is this code change will get you what you want, and it should work if that form is open in Form View.
Run this statement in the Immediate window. (You can use Ctrl+g to open the Immediate window.)
DoCmd.OpenQuery "UnitMoreInfoQ"
When Access opens the query, it will ask you to supply a value for the first parameter it identifies. The name of that parameter is included in the parameter input dialog. It will ask for values for each of the parameters.
Compare those "parameter names" to your query's SQL. Generally something is misspelled.
Using the copy of your db, DoCmd.OpenQuery("UnitMoreInfoQ") asks me for 6 parameters.
Here is what I see in the Immediate window:
? CurrentDb.QueryDefs("UnitMoreInfoQ").Parameters.Count
6
for each prm in CurrentDb.QueryDefs("UnitMoreInfoQ").Parameters : _
? prm.name : next
[Forms]![WorkOrderDatabaseF]![Text71]
[Forms]![WorkOrderDatabaseF]![ClientNameTxt]
[Forms]![WorkOrderDatabaseF]![WorkOrderNumberTxt]
[Forms]![WorkOrderDatabaseF]![TrakwareNumberTxt]
[Forms]![WorkOrderDatabaseF]![WorkOrderCompleteChkBx]
[Forms]![WorkOrderDatabaseF]![WorkOrderDueDateTxt]
Make sure there is a form named WorkOrderDatabaseF open in Form View when you run this code:
Set rec = db.OpenRecordset("UnitMoreInfoQ")
Does the [UnitMoreInfoQ] query execute properly on its own? If you mistype a field in access it will treat that field as a parameter.
ProjectMoreInfoQ and UnitMoreInfoQ are different queries... it sounds like one takes 6 parameters and the other doesn't. Look at the queries in Access and see if either have parameters defined.

Is it possible to submit data into a SQL database, wait for that to finish, and then return the ID generated from SQL, using Classic ASP?

I have an ASP form that needs to submit data to two different systems. First the data needs to go into an MS SQL database, which will get an ID. I then need to submit all that form data to an external system, along with that ID.
Pretty much everything in the code works just fine, the data goes into the database, and the data will go to the external system. The problem is I am not getting my ID back from SQL when I execute that query. I am under the impression this is happening because of how fast everything occurs in the code. The database is adding it's row at the same time my post page runs it's query to get the ID back, I think.
I need to know of a way to wait until SQL finished the insert or wait for a specific amount of time maybe. I already tried using the hacks to "sleep" with ASP, that did not help.
I am sure I could accomplish this in .Net, my background is more .Net than ASP, but this is what I have to work with on my current project.
Any ideas?
EDIT: Code from the the function writing to the DB.
driis - That was my understanding of how this should be working, but my follow up query for the ID returns nothing, so my though is that the row hasn't finished being inserted or updated yet. Maybe I am wrong on that, if so, that complicates this more. :(
Either way here is the code from the function to update the DB. Mind you this code is inherited, the rest of my project is being written by me, but I am stuck using these functions from a previous developer.
Sub DBWriteResult
Dim connLeads
Dim sSQL
Dim rsUser
Dim sErrorMsg
Dim sLeads_Connection
' Connect to the Leads database
' -------------------------------------------------------------------
sLeads_Connection = strDatabaseConnection
Set connLeads = CreateObject("ADODB.Connection")
connLeads.Provider = "SQLOLEDB.1"
On Error Resume Next
connLeads.Open sLeads_Connection
If Err.number <> 0 Then
' Bad connection display error
' -----------------------------------------------------------------
Response.Write "Database Write Error: 001 Contact Programmer"
Set connLeads = Nothing
Exit Sub
Else
' Verify the transaction does not already exist.
' -----------------------------------------------------------------------
Set rsUser = Server.CreateObject("ADODB.Recordset")
rsUser.LockType = 3
rsUser.CursorLocation = 3
sSQL = "SELECT * "
sSQL = sSQL & " FROM Leads;"
rsUser.Open sSQL, connLeads, adOpenDynamic
Response.Write Err.Description
If Err.number = 0 Then
' Add the record
' -----------------------------------------------------------
rsUser.AddNew
rsUser.Fields("LeadDate") = Date()&" "&Time()
rsUser.Fields("StageNum") = ESM_StageNum
rsUser.Fields("MarketingVendor") = ESMSourceData
rsUser.Fields("FirstName") = ESM_FirstName
rsUser.Fields("Prev_LName") = Request.Form ("Prev_LName")
rsUser.Fields("LastName") = ESM_LastName
rsUser.Fields("ProgramType") = ESM_ProgramType
rsUser.Fields("ProgramofInterest") = ESM_ProgramofInterest
rsUser.Fields("Phone1") = Phonenumber
rsUser.Fields("Phone2") = ESM_Phonenumber2
rsUser.Fields("Address1") = ESM_Address
rsUser.Fields("Address2") = ESM_Address2
rsUser.Fields("City") = ESM_City
rsUser.Fields("State") = ESM_State
rsUser.Fields("Region") = ESM_Region
rsUser.Fields("Zip") = ESM_Zip
rsUser.Fields("Country") = ESM_Country
rsUser.Fields("Email") = ESM_Email
rsUser.Fields("MilitaryBranch") = ESM_MilitaryBranch
rsUser.Fields("MilitaryStatus") = ESM_MilitaryStatus
rsUser.Fields("BestTimeToCall") = ESM_BestTimeToCall
rsUser.Fields("DateofBirth") = ESM_DateofBirth
rsUser.Update
Else
' There was an error
Response.Write "There was an error. Error code is: "&Err.number&" "&Err.Desc
End if
End If
' Close the recordset
' ---------------------------------------------------------------
Call rsUser.Close
Set rsUser.ActiveConnection = Nothing
Set rsUser = Nothing
' Destroy the connection to the database
' -------------------------------------------------------------------
Set connLeads = Nothing
End Sub
It sounds like you're trying to do this:
Insert some data in DB 1
Retrieve an ID from the inserted data
Send data + the ID to DB 2
It's been a good five years but I believe it looked something like this:
dim connStr1
connStr1 = "[connection string 1]"
dim conn1
set conn1 = server.createobject("adodb.connection")
conn1.open connStr1
dim sql
sql = " SET NOCOUNT ON " & vbCrLf & _
" INSERT FOO (a, b, c) VALUES (1, 2, 3) " & vbCrLf & _
" SET NOCOUNT OFF " & vbCrLf & _
" SELECT SCOPE_IDENTITY() "
dim rs
set rs = conn1.execute(sql)
rs.close
dim id
set id = CInt(rs(0))
conn1.close
dim connStr2
connStr2 = "[connection string 2]"
dim conn2
set conn2 = server.createobject("adodb.connection")
conn2.open connStr2
conn2.execute("INSERT FOO (id, a, b, c) VALUES (" & id & ", 1, 2, 3)")
conn2.close
Good luck, and get off my lawn!
Ok, so I figured this one out. The problem was insane, a typo. I am spoiled with .Net and the fact that if I use a variable that doesn't really exist, I get errors. I guess ASP doesn't care so much.
On the up side, driis was correct. The code does not continue until the database transaction is completed. That was my major concern, that had incorrectly assumed that was the case. I am glad I was right.
Thanks for the help, and hopefully the next time I post it'll be something better than a tyop.
;)