How to connect to Database app path - vb6 - vb6

Im trying to connect my databases(not binded/flexible) and it will run when the form activated. But in my code it kept error and didn't connected to the database. This is my last code:
Private Sub LoginForm_Activate()
Aadodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database\Login.mdb;Persist Security Info=False"
Aadodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database\login.mdb;Persist Security Info=False"
End Sub
I have ever connected it through the adodc property. But after i run it it broke if i move the folder to another folder so i tried to connect it using a flexible connectionstring.

I have found it out, the adodc should be refreshed Aadodc1.Refresh and the record source Aadodc1.RecordSource = "Select * from [table name]" must be defined. That's all :)

Related

Retrieving a image file from a website by passing credentials

Using Visual Basic 6.0. My code needs to pull picture images from a website and download to c:\temp location.
To access the website we need to pass credentials; upon successful login the images automatically downloads. Sample code:
'retrieve image from URL
getURL = "http://mrldata#abc.com:8080/mrldata/compounds/" & lnumber & ".jpg?"
Randomize
localFile = "C:\temp\" & Hour(Now()) & Minute(Now()) & Second(Now()) & Int(Rnd * 10) & ".jpg"
CopyURLToFile getURL, localFile
How can credentials be passed in order to access the website?

How to create accdb file in vb 6.0 during runtime

Someone please help me to create MS Access database .accdb extension file during runtime using VB 6.0 at a particular location (e.g. E:\MMDataBase)
& also help me in creating tables in the same database.
MS Access 2007 is already installed in my computer
thanks
The ACE database engine is essentially an extended version of Jet 4.0 and contains much of Jet 4.0 with support for the new format on top of that. As a result both the SQL DML and DDL syntax is quite similar to Jet 4.0 SQL.
I'm not sure whether installing Access 2007 installs the ACE Provider or not. Perhaps it is an optional item in the Access 2007 installer? In any case a separate Microsoft download exists that can be used to install the necessary software even when you don't have Access 2007 at all.
See 2007 Office System Driver: Data Connectivity Components
Once that's in place the process is basically identical to doing this with Jet. Example:
Private Sub CreateDB()
'Reference required:
'
' Microsoft ActiveX Data Objects 2.5 Library (or later).
'
'OLEDB Provider required:
'
' Access Database Engine 2007.
Dim catDB As Object
Dim cnDB As ADODB.Connection
Set catDB = CreateObject("ADOX.Catalog")
With catDB
.Create "Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source='D:\sample.accdb'"
Set cnDB = .ActiveConnection
End With
Set catDB = Nothing
With cnDB
.Execute "CREATE TABLE ClassDates(" _
& "Id IDENTITY CONSTRAINT PK_UID PRIMARY KEY," _
& "Student TEXT(12) WITH COMPRESSION NOT NULL," _
& "ClassDate DATETIME NOT NULL," _
& "PaidFor YESNO DEFAULT False," _
& "CONSTRAINT StudentDates UNIQUE (" _
& "Student, ClassDate))", , _
adCmdText Or adExecuteNoRecords
.Close
End With
End Sub

ORA-01019 connecting to Oracle from Excel

I have installed Oracle 10g Express Edition. When try to test the connection I am getting the error "Error while trying to retrieve text for error ORA-01019".
Below is my code.
strConnection = "Driver={Microsoft ODBC for
Oracle};Server=Servername;Uid=username;Pwd=password;"
Set conn = CreateObject("ADODB.Connection")
conn.Open strConnection
conn.Close
Set conn = Nothing
Thanks in advance
I had the following error occur recently.
System.Runtime.InteropServices.COMException (0x80004005): ORA-01019: unable to allocate memory in the user side
at ADODB.ConnectionClass.Open(String ConnectionString, String UserID, String Password, Int32 Options)
I managed to resolve the problem by simply modifying my connection string.
from:
"Provider=MSDAORA.1;Data Source=tprss;Persist Security Info=True;User ID=myUser;Password=myPassword"
To:
"Provider=MSDASQL;Data Source=tprss;Persist Security Info=True;User ID=myUser;Password=myPassword"
someone modified/updated the components on the box.
"ORA-01019 unable to allocate memory in the user side
Cause: The user side memory allocator returned an error.
Action: Increase the size of the process heap or switch to the old set of calls."
Followup from the comments:
Could you try this code?
Dim Cn As ADODB.Connection
Dim CP As ADODB.Command
Dim Rs As ADODB.Recordset
Dim Conn As String
Dim QSQL As String
'Connect to Oracele server begin
Conn = "DRIVER={ORACLE ODBC DRIVER};SERVER=Service name;UID=username;PWD=password;DBQ=Service name;DBA=W;APA=T;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;FRL=F;MTS=F;CSR=F;PFC=10;TLO=O;"
Set Cn = New ADODB.Connection
With Cn
.ConnectionString = Conn
.CursorLocation = adUseClient
.Open
End With
If Cn.State = adStateOpen Then
MsgBox "Connection successful."
End If
'Connect to Oracle server end
'close connection begin
Cn.Close
Set Cn = Nothing
Set CP = Nothing
'close connection end
(This didnt fit in a Comment box)
You need at least one driver. The oracle driver is best but Microsoft Driver will work too.
Lets first try to make a connection string. Right click on your desktop and the create a new .txt file.
Now rename your textfile to something.udl
Double click on the udl file. Go to "Provider" and select Microsoft OLEDB Provider for Oracle. Then click on next. In the server name field you fill in your TNS name. Then username and password and put a V inside "Allow saving password" (we will need this) And click on test connection. Make sure this works.
If it works then click on OK. Now open the UDL file with a text editor. You will see something similar to:
[oledb]
; Everything after this line is an OLE DB initstring
Provider=MSDAORA.1;Password=yourpw;User ID=youruser;Data Source=yourTNS;Persist Security Info=True
Copy this part into your connection string:
Provider=MSDAORA.1;Password=yourpw;User ID=youruser;Data Source=yourTNS
Now your connection string should look like:
Conn = "Provider=MSDAORA.1;Password=yourpw;User ID=youruser;Data Source=yourTNS"
I hope this works.
We had the same problem, specifically on Windows 7 when using the Microsoft OleDb driver from VB6.
Following the instructions in this post fixed out problem:
http://prasanth4microsoft.blogspot.com/2010/11/windows7-excel-vba-ora-01019-unable-to.html
I had this problem also but it is on win10.. After I have tried a lots of different solution from web .. Finally.. it worked to change connection string to fix this problem.. But I changed "Provider=MSDAORA.1" to "Provider=OraOLEDB.Oracle"

Whats the best way to Programmatically Process New Email Messages and Store Attachments

I have several clients/vendors that distribute reports to me via email. Some of these files are enormous, and need to be removed from email and saved on a file share for processing, as well as to control mailbox size.
Can anyone provide guidance on their recommended method of automatically downloading and saving attachments.
I am in a MS Windows Environment (Client & Server Computers). Emails are on an Microsoft Exchange 2003 Email Server.
Preferred use of Microsoft Technology for consistency across solutions (C#), however I am open to any suggestions, be it C#, VBScript, Perl, Java, Components I should purchase, etc..
Scenario
Each Day bob#whysendmereportsbyemail.com sends an email with the subject "Activity Report for YYYY-MM-DD" to me at
john#myemailaddress.com
Each Email has an attachment named "ActivityReport-YYYY-MM-DD-HH-MI-SS.xls" which I need to save on my filesystem at
"C:\FilesFromBob\ActivityReport-YYYY-MM-DD-HH-MI-SS.xls"
Thanks in advance for any assistance.
Exchange 2003 provides a WebDav API which you can use to access emails, contacts etc.. from a user's account.
There's a few answers about accessing a user's Exchange inbox on SO already. I've previously used this approach for almost exactly the situation you outline, and once you work out the WebDav API model and the structure of the requests and responses, it's not too difficult to extract emails and their attachments.
There are other ways to interact with Exchange 2003 (outlined on SO here), but I've only tried the WebDav approach because it seemed the most reliable.
I finally wrote the code to store messages from Outlook
Unfortunately this code runs from within Outlook, so Outlook has to be open.
I did not yet investigate how to schedule the run, but now its easy to do
Sub SaveOutlookFileAttachments()
Dim oStores As Outlook.Stores
Dim oStore As Outlook.Store
Dim oFolders As Outlook.Folders
Dim oFolder As Outlook.Folder
Dim destFolder As String
Dim oItems As Outlook.Items
Dim oMsg As Outlook.MailItem
Dim oAttachments As Outlook.Attachments
Dim oAttachment As Outlook.Attachment
Dim oExplorer As Outlook.Explorer
destFolder = "\\NetworkShare\OrderDetailReport\"
On Error Resume Next
Set oStores = Application.Session.Stores
For Each oStore In oStores
If oStore.DisplayName = "Inbox" Then
oFolders = oStore.GetSearchFolders
For Each oFolder In oFolders
oItems = oFolder.Items
For Each oMsg In oItems
oAttachments = oMsg.Attachments
For Each oAttachment In oAttachments
If InStr(1, oAttachment.FileName, "orderdetail_", vbTextCompare) Then
'MsgBox ("This File Needs to be Saved: " & oAttachment.FileName)
oAttachment.SaveAsFile (destFolder & oAtch.DisplayName)
End If
Next
Next
Next
End If
Next
End Sub

Is there a way to check the MS Security Center for virus protection status?

We are in a Windows environment and looking to automate this process for non-company machines. If a vendor comes on site, we'd like to be able to have him/her hit a website that can perform a quick scan of the workstation to determine if they have the proper MS KB patches and if their virus scanner dats are up to date.
I can scan for the KB updates relatively easy, what I'm having a hard time finding is a way to check the virus dat status and since there are so many different engines out there, it seemed to make sense to use the (built into XP at least) proprietary MS security center stuff.
Eventually we'd like to have our routers redirect non-company machines to a website that will force validation, but until that point it will be a manual process.
Any thoughts?
In Windows Vista there are some new APIs to interface with the Security Center component status: http://msdn2.microsoft.com/en-us/library/bb963845(VS.85).aspx
Through WMI, here's a VBS code snippet I checked out on http://social.msdn.microsoft.com/forums/en-US/windowssecurity/thread/bd97d9e6-75c1-4f58-9573-9009df5de19b/ to dump Antivirus product information:
Set oWMI = GetObject
("winmgmts:{impersonationLevel=impersonate}!\\.\root\SecurityCenter")
Set colItems = oWMI.ExecQuery("Select * from AntiVirusProduct")
For Each objAntiVirusProduct In colItems
msg = msg & "companyName: " & objAntiVirusProduct.companyName & vbCrLf
msg = msg & "displayName: " & objAntiVirusProduct.displayName & vbCrLf
msg = msg & "instanceGuid: " & objAntiVirusProduct.instanceGuid & vbCrLf
msg = msg & "onAccessScanningEnabled: "
& objAntiVirusProduct.onAccessScanningEnabled & vbCrLf
msg = msg & "productUptoDate: " & objAntiVirusProduct.productUptoDate & vbCrLf
msg = msg & "versionNumber: " & objAntiVirusProduct.versionNumber & vbCrLf
msg = msg & vbCrLf
Next
WScript.Echo msg
For AVs that don’t report to WMI or for AVs which WMI retains state info after the AV is uninstalled (there are instances of both cases) you may wish to consider the OPSWAT library.
You will need to write and deploy a light client from your website to utilize the library to machines to be interrogated.
The library utilizes WMI for security apps that correctly support WMI and proprietary methods to detect AVs and their dat status for those that don’t.

Resources