TDConnection in Excel VBA - vba

I am trying to connect to HPQC though vbscript in excel. I have already added the OTA library to Reference.
When I am trying to instantiate an object as TDConnection,
Global tdc As TDConnection
Set tdc = new TDConnection
its throwing an error:
Run-time error '429':
ActiveX component can't create object.
I used the below code to check:
Sub Connect()
Dim tdc as TDConnection
Dim url as String
Dim Domain as String
Dim Project as String
Dim username as String
Dim Password as String
url = "http://qc.abcdef.com"
Domain = "NNNN"
Project = "NNNNNNN"
username = "ABCD"
Pasword = "XYZ"
Disconnect 'Disconnects any open connections
If (tdc Is Nothing) Then Set tdc = New TDConnection
If (tdc Is Nothing) Then GoTo ConnectionErr
tdc.InitConnectionEx url 'Initiate Connection
tdc.Login username, Password
tdc.Connect Domain, Project
MsgBox "Connection Established"
Exit Sub
ConnectionErr:
MsgBox "Connection Error"
End Sub
Then ran from cmd the below command
C:\Windows\SysWOW64> wscript.exe "C:\...\QC.vbs"
but facing error
Please help!

Try running your VB script with command prompt using specific cscript -
C:\WINDOWS\SysWOW64>cscript.exe ".... .vbs"
For more info refer https://community.hpe.com/t5/Quality-Center-ALM-Practitioners/ActiveX-component-can-t-create-object-TDApiOle80-TDConnection/td-p/4742677

Related

PowerShell remote call. Access is denied from webserver

i write a code for remote access for exchange powershell from asp.net application to enable remote mail using vb.net and exchange 2016
the command run successfully from my visual studio debug
but when i put in iis web server it's giving me
Connecting to remote server "" failed with the following error
message : Access is denied
this is is the code
Function enableRemoteEmail(ByVal samaccount As String, ByVal email As String) As String
Dim ServerUri As String = "http://{mailserver}/powershell"
Dim SchemaUri As String = "http://schemas.microsoft.com/powershell/Microsoft.Exchange"
Dim userName As String = AccountOperatorLogon
Dim password As New System.Security.SecureString
For Each x As Char In AccountOperatorPassword
password.AppendChar(x)
Next
Dim PSCredential As New PSCredential(userName, password)
Dim ConnectionInfo As WSManConnectionInfo = New WSManConnectionInfo(New Uri(ServerUri), SchemaUri, PSCredential)
ConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic
Dim RemoteRunspace As Runspace = RunspaceFactory.CreateRunspace(ConnectionInfo)
Dim RemotePowerShell As PowerShell = PowerShell.Create
RemotePowerShell.AddCommand("Enable-RemoteMailbox")
RemotePowerShell.AddParameter("Identity", samaccount)
RemotePowerShell.AddParameter("RemoteRoutingAddress",email )
RemotePowerShell.AddParameter("Credential", PSCredential)
' Open the remote runspace on the server.
RemoteRunspace.Open()
' Associate the runspace with the Exchange Management Shell.
RemotePowerShell.Runspace = RemoteRunspace
Dim TheResult As Collection(Of PSObject)
Dim TheResultString As String = ""
TheResult = RemotePowerShell.Invoke
For Each RSLT As PSObject In TheResult
TheResultString += RSLT.ToString() + "<br/>"
Next
RemoteRunspace.Close()
' Invoke the Exchange Management Shell to run the command.
Return TheResultString
End Function
i found the solution for anyone have the same problem
create user as a member of (Recipient Management group)
IIS change (for exchange server) navigate to IIS Manager | Default Website | PowerShell Change the physical path from: C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxy\PowerShell to: C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\PowerShell
3.After the change: IISRESET
and it will work fine

error -2147467259 (80004005) .net mdb

I am calling a vb.net function of a dll from below VBA code in MDB.
I am calling Get_GDW_data_final sub from immediate Window.
Public Sub Get_GDW_data_final()
Dim r As New Get_GDW_Data.GDW
MsgBox r.DetailedWork()
End Sub
I have created Get_GDW_Data.dll added reference of it in MDB.
The coding of class is as below.
Public Class GDW
Public Function DetailedWork()
Dim lastrow As Long
Dim ADODBcnn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Access8\W156_RocketOffset_Backup.mdb;Persist Security Info=False;Mode=read")
Dim ADODBcmd As New OleDb.OleDbCommand
Dim ADODBcmd1 As New OleDb.OleDbCommand
Dim ADODBrst As OleDb.OleDbDataReader
ADODBcnn.Open()
ADODBcmd.CommandText = "select count(*) from input"
lastrow = ADODBcmd.ExecuteScalar()
ADODBcnn.Close()
Return lastrow.ToString()
End Function
End Class
Here I am getting error
Run-time Error -2147467259 (80004005)
The database has been put in a state by admin or machine 'Rachit' that prvents it from being opened or locked.
I discovered what the problem was:
It's a Limitation of Access that you can not access a table of a database using a dll from which you are calling the function :-)
INPUT is a reserved word, so try:
ADODBcmd.CommandText = "select count(*) from [input]"

Error 3420: Object invalid or no longer set

I'm having trouble with a odbc connection in excel-vba tool.
Public connString As Connection
Sub login()
logout
Set wrkODBC1 = CreateWorkspace("NewODBC", "admin", "", dbUseODBC)
Set connString= wrkODBC1.OpenConnection("odbc-database", dbDriverNoPrompt, , "ODBC;uid=user;pwd=passwrd;DSN=odbc-database")
End Sub
Sub logout()
On Error Resume Next
connString.Close
wrkODBC1.Close
On Error GoTo 0
End Sub
When running this code:
login
txt = "SELECT [col1],[col1] FROM database.[dbo].[table]"
sqlToWorksheet sheet, connString, txt
Sub sqlToWorksheet(sheet, conn, sqlString)
Set temp = conn.OpenRecordset(sqlString, dbOpenSnapshot)
When conn.OpenRecordset is executed I get the error: Error 3420: Object invalid or no longer set. Anyone knows what wrong? Works with my other odbc connections. The database is a mssqlserver2012.
I forgot this instantiate wrkODBC1, working now.

VB.net UploadFile

I am trying to send a file up to a server using VB.net. I have found many examples exclaiming it to be simple to do but none of the examples I have found have worked.
The current one I am trying is in the following code:
Dim WithEvents wc As New System.Net.WebClient()
Private Sub oWord_DocumentBeforeClose(ByVal Doc As Microsoft.Office.Interop.Word.Document, ByRef Cancel As Boolean) Handles oWord.DocumentBeforeClose
Try
Using wc As New System.Net.WebClient()
wc.Credentials = New NetworkCredential("ehavermale", "ernie1")
wc.UploadFile("http://192.168.95.1:83/GraphTest.txt", "C:\Users\EHovermale\Desktop\GraphTest.txt")
End Using
Catch ex As Exception
MsgBox("Error:" + ex.Message)
End Try
'System.IO.File.Delete("C:\Users\EHovermale\Desktop\GraphTest.txt")
MsgBox("See Ya")
End Sub
When I run this program I get the Error: An Exception has occurred during a WebClient Request.
I have access to read/write files to the server I am trying to hit.
Is there another way to upload files or is something wrong with my code for this way?
Thank you!
Since there is no HTTP service to handle the file upload, you could save the file directly using VBA's Scripting.FileSystemObject. This will work if you can access the network share from wherever your document is located. Remember that if the document is moved to another computer then this may not work.
Public Sub MoveFile()
Dim fso As Object
Dim sourceFile As String
Dim targetFile As String
' You must add reference to "Microsoft Scripting Runtime" to your document
' Tools > References... > scroll down the item.
Set fso = CreateObject("Scripting.FileSystemObject")
sourceFile = "C:\Users\davidr\Desktop\foo.txt"
targetFile = "\\192.168.95.1:83\foo.txt"
' Test if destination file already exists
If fso.FileExists(targetFile) Then
MsgBox ("This file exists!")
Exit Sub
End If
' Move the file
fso.CopyFile sourceFile, targetFile
Set fso = Nothing
End Sub

Error connecting to DB from VB to Access

I have an Access project where I want a label to be showed when a form is opened only if a query returns a result.
I have the following code:
Private Sub Form_Load()
Dim stSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = DBEngine.Workspaces(0).Databases(0)
Dim cn As DAO.Connection
Set cn = DAO.Connection
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.Open stdbName
stSQL1 = "SELECT * FROM tbl_lessons"
Set rs = db.OpenRecordset(stSQL1, dbOpenDynaset)
If (rs Is Not Nothing) Then
If (rs.GetRows() > 0) Then
lbl_alert.Visible = True
Else
lbl_alert.Visible = False
End If
End If
When I try to open the form I'm getting the following error:
Compile error:
Method or data member not found
I'm using Access 2007 with VB7
Can someone please help?
Note - when compile errors happen in VBA, a line of code is always highlighted. Looking carefully at the highlighted line will help you figure out what you did wrong. Also note that you should always compile your code before attempting to run the form. (open the "Debug" menu > click "Compile VBAProject" or the like.)
There appears to be a bunch of problems, and you'll probably have to address them one at a time. just keep fixing issues and re-compiling your code.
1cn.Open stdbName1
--> stdbname is not defined anywhere in the code you showed us.
Dim stSQL As String
--> You defined your connection string as stSQL but in your code you used: stSQL1 = "...". Fix your variable name.