|
Graham Irons wrote: I've only been programming in VB for about 25 years So the 90's were your training ground, I started writing macros in Excel 1 somewhat earlier. There seem to be a plethora of old farts here on CP
Some places won't let you write to the registry and there is no guarantee someone doesn't want to go fiddle with the settings. User data folder is more specific if required and no more difficult to use than the registry. It is also probably faster.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I am trying to download pricing data from Commonwealth Edison via their recently published Hourly Pricing API. This uses GETs from defined HTTPS URLs, and I have confirmed that typing the appropriate calls into a Web Browser results in the return of the data in the expected format. My code is as follows:
wc = New WebClient
strGet = "https://hourlypricing.comed.com/api?type=5minutefeed&datestart=201708040835&dateend=201708041035"
strResult = wc.DownloadString(strGet)
In the real Application, strGet is put together by other code, but I have checked that this is working correctly. The code here aborts with a ThreadAbortException in System.dll at the DownloadString call. If I substitute an HTTP location on one of my sites for Comed's HTTPS location in strGet, everything works as it should, and the file data is retrieved.
I have researched this and tried a number of suggested 'cures' for problems with HTTPS connections under VB.NET, but the problem persists.
Helpful suggestions welcomed!
|
|
|
|
|
 I've just tried that code, and it works fine.
[{"millisUTC":"1501860900000","price":"2.2"},{"millisUTC":"1501860600000","price":"2.2"},{"millisUTC":"1501860300000","price":"1.0"},{"millisUTC":"1501860000000","price":"0.7"},{"millisUTC":"1501859700000","price":"1.4"},{"millisUTC":"1501859400000","price":"2.1"},{"millisUTC":"1501859100000","price":"2.1"},{"millisUTC":"1501858800000","price":"2.5"},{"millisUTC":"1501858500000","price":"2.6"},{"millisUTC":"1501858200000","price":"2.6"},{"millisUTC":"1501857900000","price":"2.7"},{"millisUTC":"1501857600000","price":"2.6"},{"millisUTC":"1501857300000","price":"2.7"},{"millisUTC":"1501857000000","price":"2.7"},{"millisUTC":"1501856700000","price":"3.2"},{"millisUTC":"1501856400000","price":"2.5"},{"millisUTC":"1501856100000","price":"2.6"},{"millisUTC":"1501855800000","price":"2.9"},{"millisUTC":"1501855500000","price":"2.6"},{"millisUTC":"1501855200000","price":"2.5"},{"millisUTC":"1501854900000","price":"2.7"},{"millisUTC":"1501854600000","price":"2.5"},{"millisUTC":"1501854300000","price":"2.4"},{"millisUTC":"1501854000000","price":"2.4"},{"millisUTC":"1501853700000","price":"2.4"}]
There must be something else going on in your application, or a problem on your network.
Can you request the url from a browser running on the server?
Is there a firewall in the way?
Is your server configured to force an SSL v2 / v3 connection, or otherwise disabling TLS?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
My browser delivers the content of the URL without problems.
I do have a regular (McAfee) firewall, but, as noted, it is not interfering with the browser accessing the same location.
I have no idea how Comed's server is configured. I have a fairly standard install of Windows 10, and am having no difficulty accessing other sites, including a lot which use SSL.
Running exactly the code I gave as a standalone function produced the same error on my system, but it also produced the following 'informational' message from VS: "Evaluation requires a thread to run temporarily. Use the Watch window to perform the evaluation." I wonder if this is a debugger issue. I have to drop this for now, but will return to it and report back in a couple of days when I can get back to it.
|
|
|
|
|
The problem seems to be what I can only describe as a deficiency in the Visual Studio environment - the clue was the information message described in my previous response.
My usual way of testing an isolated Sub or Function while I am developing an application is either to invoke it directly from the Immediate Window, or, if this is not convenient (as it frequently isn't), to write a stub Sub which uses it and invoke that from the Immediate Window. This has always worked for me before. It appears that there is an issue with doing this to test (at least some) WebClient code, presumably because of some aspect of how code invoked from the Immediate Window is interpreted and run. If I put the code clipping from my first message in the Form_Load Function of a Windows Forms App and run the App, the code runs normally and returns the expected JSON string. If I put the identical code in a Public Sub and invoke the Sub from the VS Immediate Window, it throws the ThreadAbortException that I originally described. Perhaps the most bizarre aspect of this is the fact that the misbehavior is dependent on the URL in the request being an HTTPS one - as I noted, requests involving HTTP URLs are handled correctly, even when the code is run from the Immediate Window.
|
|
|
|
|
I am writing a client program in VB6 which will interface to a server over HTTP. The company who runs the server provided me with a certificate file called SomeCertificate.p12.
My program is running on Windows XP. This is the operating system the customer is using.
I am trying to find how to use this certificate when sending requests to the server.
Here is what I have done so far:
- Copied the certificate file to my test computer.
- Using Internet Explorer V8, I did "Tools|Internet Options|Content|Certificates|Trusted Root Authorities" and imported the certificate.
- Installed the winhttpcertcfg tool.
- Ran the following from command prompt:
"winhttpcertcfg -i SomeCertificate.p12 -c LOCAL_MACHINE\My -a COMPUTERNAME\USERNAME -p PasswordFromServerCompany"
the output was something like this. I replaced the different tokens with dummy strings:
Imported certificate:
CN=string1
OU=string2
O=string3
L=string4
C=string5
Private key access has already been granted for account: COMPUTERNAME\USERNAME
- My VB6 code looks something like this:
Private WithEvents m_ServerObj As WinHttpRequest Set m_ServerObj = New WinHttpRequest m_ServerObj.Open "GET", "https://serveraddress"
Call m_ServerObj.SetClientCertificate("LOCAL_MACHINE\Personal\SomeCertificate")
m_ServerObj.Send TextToSend
The Send call causes an exception: "A certificate is required to complete client authentication"
I tried different strings in the SetClientCertificate call but I keep getting the same error.
I'd appreciate any help and tips. What am i doing wrong? Is my code wrong? Did I use winhttpcertcfg incorrectly?
thank you.
modified 25-Jul-17 2:12am.
|
|
|
|
|
|
Thank you.
I think the "-s" option cannot be used with "-i". I tried to add it, but the utility just printed it's syntax text, as if the parameters were incorrect.
Like so:
winhttpcertcfg -i CertificateFile.p12-c LOCAL_MACHINE\My -s CertifiaceFile
-a COMPUTERNAME\USERNAME -p PASSWORD
on the other hand, it was accepted with "-l":
winhttpcertcfg -l -c LOCAL_MACHINE\MY -s CertificateFile
|
|
|
|
|
VB6 has effectively been "dead" for over 15 years. You'll struggle to find documentation or support for it, since most people have moved to .NET by now. With the release of Visual Studio Community[^], so long as you're within the limits, you can upgrade for free.
The only issue is, Windows XP doesn't support anything above .NET 4.0. But support for Windows XP ended over three years ago[^]. Aside from the occasional notable exception[^], your customer's computers have not received a security update for any vulnerability discovered in that time. Since it seems they're connected to the internet, they're ticking time-bombs waiting to destroy the network.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The fact i am using VB6 right now should not matter. The program is using Windows winhttp.dll, a COM object. I could have used C++ and still have the same problem.
|
|
|
|
|
His commentary on VB6 was not directed at the problem at hand but the code you're writing by your language of choice. Since VB6 has been dead for so long, how long is it going to be before the runtime no longer works on Windows and you, or some successor, will be rewriting this thing in a modern language?
|
|
|
|
|
The server company sent me a .PEM certificate to install. Once I did that, the problem was solved.
Thank you.
|
|
|
|
|
How to do an exe on visual studio attach to sqlite. I have tried it and voicke code error: Unable to open the database file
It makes me self that I search on the net may not have concrete answer that helps me. I was advised sqlite to embed the database but how to do it ?? I need your help
|
|
|
|
|
Member 13322378 wrote: Unable to open the database file
Perhaps that file does not exist. This is the first thing to note, if the file does not exist how can you even read it?
Also, you did not mention which language you are using? You are in the Visual Basic forum and only mentioning Visual Studio here. I will assume you want to use the C# library (or VB.NET, they are both same).
c# - SQLIte unable to open database - Stack Overflow
Secondly, it might be that the server or program requires some additional permissions so that the library can properly connect to the database. There is a long conversation and they all boil down to the permissions (read and write, both) of your database + directory where that file is, so that SQLite can easily update the data in the database.
Fixing Sqlite error "unable to open database file"
For simplest of the tasks, you should try using this Firefox addon for SQLite manager, and see if it can access and open the database for you: SQLite Manager :: Add-ons for Firefox... It will help you understand whether there is a problem or not.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thanks mr.
All my apologies I program under visual studio in csharp. And I installed sqlite server 3.9.1. I would like to know if I need to uninstall and use firefox ??
And how do I go about doing the exe and install it on another computer
|
|
|
|
|
Member 13322378 wrote: I program under visual studio in csharp. So why post in the Visual Basic forum? But, be that as it may, you can take a look at System.Data.SQLite[^]
|
|
|
|
|
Since the repost in the VS-category is newer than this thread, I'm assuming you're still struggeling with the concept. SQLite is not a server-database, it is meant as a lightweight database-solution for local usage of your application. That gives SQLite some advantages and some disadvantages over a server-product.
Richard linked you the System.Data.SQLite page; that wiki explains how to use and deploy SQLite. You'll probably end up xcopying two files along with your executable.
Some other points; if you have been "searching for five months" than you have wasted time that you could have used to read the documentation. Next, "help me" is not a decent subject-line. Everyone who posts here is looking for help - and your question is rather specific to SQLite and C#.
So, post your code, and let us see how you connect to your datafile. Once we have code, we can talk about possible locations where things can go wrong and what it is exactly that you need to verify.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi
Sorry for the topic
"help me"
I used the dataset
Here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
namespace ACode
{
public partial class Form1 : Form
{
public static string randomstring(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWYZ0123456789";
Random random = new Random();
return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
}
public Form1()
{
InitializeComponent();
}
private void infoCodeBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.infoCodeBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.dBCodeAleatoireDataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
this.infoCodeTableAdapter.Fill(this.dBCodeAleatoireDataSet.InfoCode);
}
private void btn100_Click(object sender, EventArgs e)
{
labelAffichage.Text = randomstring(4);
codeTextBox.Text = labelAffichage.Text;
prixCodeTextBox.Text = "100";
}
private void btn250_Click(object sender, EventArgs e)
{
labelAffichage.Text = randomstring(5);
codeTextBox.Text = labelAffichage.Text;
prixCodeTextBox.Text = "250";
}
private void btn500_Click(object sender, EventArgs e)
{
labelAffichage.Text = randomstring(6);
codeTextBox.Text = labelAffichage.Text;
prixCodeTextBox.Text = "500";
}
}
}
|
|
|
|
|
Where is the connectionstring? I do not see anything that references your database-file.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi
Please forgive me, this may be a simple answer for some. I have self taught myself VB.net and have developed some software for myself. I often get code samples for hardware that i use, but it is in C#. I have used code converters, but I still seem to get issues. The major issue I have is below. The C# code works perfectly, but the VB code gives me a "Object reference not set to an instance of an object.'" error when I call the connect sub. Please help.
C# Code
using SPORTident;
using System.Windows.Forms;
using SPORTident.Communication;
using System;
namespace SportidentMinimal
{
public partial class MainForm : Form
{
public Reader reader;
public MainForm()
{
InitializeComponent();
reader = new Reader
{
WriteBackupFile = true,
BackupFileName = System.IO.Path.Combine(Environment.CurrentDirectory, $@"backup\{DateTime.Now:yyyy-MM-dd}_stamps.bak")
};
reader.DeviceConfigurationRead += new DeviceConfigurationReadEventHandler(reader_DeviceConfigurationRead);
reader.InputDeviceChanged += new ReaderDeviceChangedEventHandler(reader_InputDeviceChanged);
reader.InputDeviceStateChanged += new ReaderDeviceStateChangedEventHandler(reader_InputDeviceStateChanged);
reader.CardRead += new SPORTident.DataReadCompletedEventHandler(reader_CardRead);
}
private void reader_DeviceConfigurationRead(object sender, StationConfigurationEventArgs e)
{
writeLog("StationConfigRead, OperatingMode: " + e.Device.OperatingMode);
writeLog("StationConfigRead, LegacyProtocolMode: " + e.Device.LegacyProtocolMode);
writeLog("StationConfigRead, AutoSend: " + e.Device.AutoSendMode);
writeLog("StationConfigRead, FirmwareVersion: " + e.Device.FirmwareVersion);
writeLog("StationConfigRead, CodeNumber: " + e.Device.CodeNumber);
writeLog("StationConfigRead, SerialNumber: " + e.Device.SerialNumber);
}
private void reader_InputDeviceStateChanged(object sender, ReaderDeviceStateChangedEventArgs e)
{
writeLog("InputDeviceStateChanged: " + e.PreviousState + " => " + e.CurrentState);
}
private void reader_InputDeviceChanged(object sender, ReaderDeviceChangedEventArgs e)
{
writeLog("InputDeviceChanged: " + e.PreviousDevice + " => " + e.CurrentDevice);
}
private void reader_CardRead(object sender, SportidentDataEventArgs e)
{
SportidentCard card = e.Cards[0];
writeLog("Card read: " + card.Siid);
}
private void button_refresh_Click(object sender, EventArgs e)
{
writeLog("Refresh pressed");
clearSIDevices();
getSIDevices();
}
private void button_sportidentConnect_Click(object sender, EventArgs e)
{
writeLog("Connect pressed");
try
{
connect();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button_sportidentDisconnect_Click(object sender, EventArgs e)
{
writeLog("Disconnect pressed");
disconnect();
}
private void writeLog(string text)
{
if (listBox_log.InvokeRequired)
{
listBox_log.Invoke(new Action(() => writeLog(text)));
}
else
{
listBox_log.Items.Add(text);
listBox_log.SelectedIndex = listBox_log.Items.Count - 1;
listBox_log.SelectedIndex = -1;
}
}
private void clearSIDevices()
{
writeLog("Clearing list of devices");
comboBox_sportidentDevices.Items.Clear();
}
private void getSIDevices()
{
writeLog("Scanning for available devices");
ReaderDeviceInfo.GetAvailableDeviceList();
foreach (ReaderDeviceInfo device in ReaderDeviceInfo.AvailableDevices)
{
comboBox_sportidentDevices.Items.Add(device);
writeLog("Adding device: " + device.DeviceName);
}
if (comboBox_sportidentDevices.Items.Count > 0)
{
writeLog("Found " + comboBox_sportidentDevices.Items.Count + " devices");
comboBox_sportidentDevices.SelectedIndex = 0;
}
else
{
writeLog("No devices found");
}
}
private void connect()
{
ReaderDeviceInfo readerDeviceInfo = (ReaderDeviceInfo)(comboBox_sportidentDevices.SelectedItem);
reader.InputDevice = readerDeviceInfo;
reader.OutputDevice = new ReaderDeviceInfo(ReaderDeviceType.None);
reader.OpenInputDevice();
reader.OpenOutputDevice();
comboBox_sportidentDevices.Enabled = false;
button_refresh.Enabled = false;
button_sportidentConnect.Enabled = false;
button_sportidentDisconnect.Enabled = true;
}
private void disconnect()
{
comboBox_sportidentDevices.Enabled = true;
button_refresh.Enabled = true;
button_sportidentConnect.Enabled = true;
button_sportidentDisconnect.Enabled = false;
reader.CloseInputDevice();
}
}
}
VB.NET Code
Imports SPORTident
Imports SPORTident.Communication
Public Class Results_Capture_Enduro
Public reader As Reader
Public Sub New()
InitializeComponent()
reader = New Reader() With {
.WriteBackupFile = True,
.BackupFileName = System.IO.Path.Combine(Environment.CurrentDirectory, "backup\{DateTime.Now:yyyy-MM-dd}_stamps.bak")
}
AddHandler reader.DeviceConfigurationRead, New DeviceConfigurationReadEventHandler(AddressOf reader_DeviceConfigurationRead)
AddHandler reader.InputDeviceChanged, New ReaderDeviceChangedEventHandler(AddressOf reader_InputDeviceChanged)
AddHandler reader.InputDeviceStateChanged, New ReaderDeviceStateChangedEventHandler(AddressOf reader_InputDeviceStateChanged)
AddHandler reader.CardRead, New SPORTident.DataReadCompletedEventHandler(AddressOf reader_CardRead)
End Sub
Private Sub reader_DeviceConfigurationRead(sender As Object, e As StationConfigurationEventArgs)
writeLog("StationConfigRead, OperatingMode: " & e.Device.OperatingMode.ToString)
writeLog("StationConfigRead, LegacyProtocolMode: " & e.Device.LegacyProtocolMode.ToString)
writeLog("StationConfigRead, AutoSend: " & e.Device.AutoSendMode.ToString)
writeLog("StationConfigRead, FirmwareVersion: " & e.Device.FirmwareVersion.ToString)
writeLog("StationConfigRead, CodeNumber: " & e.Device.CodeNumber.ToString)
writeLog("StationConfigRead, SerialNumber: " & e.Device.SerialNumber.ToString)
End Sub
Private Sub reader_InputDeviceStateChanged(sender As Object, e As ReaderDeviceStateChangedEventArgs)
writeLog("InputDeviceStateChanged: " & e.PreviousState.ToString & " => " & e.CurrentState.ToString)
End Sub
Private Sub reader_InputDeviceChanged(sender As Object, e As ReaderDeviceChangedEventArgs)
writeLog("InputDeviceChanged: " & e.PreviousDevice.ToString & " => " & e.CurrentDevice.ToString)
End Sub
Private Sub reader_CardRead(sender As Object, e As SportidentDataEventArgs)
MessageBox.Show("got here")
Dim card As SportidentCard = e.Cards(0)
writeLog("Card read: " & card.Siid.ToString)
End Sub
Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
writeLog("Refresh pressed")
clearSIDevices()
getSIDevices()
End Sub
Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
writeLog("Connect pressed")
connect()
End Sub
Private Sub btnDisconnect_Click(sender As Object, e As EventArgs) Handles btnDisconnect.Click
writeLog("Disconnect pressed")
disconnect()
End Sub
Private Sub writeLog(Text As String)
If listBox_log.InvokeRequired Then
listBox_log.Invoke(New Action(Sub() writeLog(Text)))
Else
listBox_log.Items.Add(Text)
listBox_log.SelectedIndex = listBox_log.Items.Count - 1
listBox_log.SelectedIndex = -1
End If
End Sub
Private Sub clearSIDevices()
writeLog("Clearing list of devices")
cbbSportIdentDevices.Items.Clear()
End Sub
Private Sub getSIDevices()
writeLog("Scanning for available devices")
ReaderDeviceInfo.GetAvailableDeviceList()
For Each device As ReaderDeviceInfo In ReaderDeviceInfo.AvailableDevices
cbbSportIdentDevices.Items.Add(device)
writeLog("Adding device: " & device.DeviceName.ToString)
Next
If cbbSportIdentDevices.Items.Count > 0 Then
writeLog("Found " & cbbSportIdentDevices.Items.Count.ToString & " devices")
cbbSportIdentDevices.SelectedIndex = 0
Else
writeLog("No devices found")
End If
End Sub
Private Sub connect()
Dim readerDeviceInfo As ReaderDeviceInfo = CType((cbbSportIdentDevices.SelectedItem), ReaderDeviceInfo)
reader.InputDevice = readerDeviceInfo
reader.OutputDevice = New ReaderDeviceInfo(ReaderDeviceType.None)
reader.OpenInputDevice()
reader.OpenOutputDevice()
End Sub
Private Sub disconnect()
'reader = New Reader()
cbbSportIdentDevices.Enabled = True
reader.CloseInputDevice()
End Sub
End Class
The exception seems to come when I have called the connect sub. I am assuming it doesn't like the 4 lines where I reference "reader".
Private Sub connect()
Dim readerDeviceInfo As ReaderDeviceInfo = CType((cbbSportIdentDevices.SelectedItem), ReaderDeviceInfo)
reader.InputDevice = readerDeviceInfo
reader.OutputDevice = New ReaderDeviceInfo(ReaderDeviceType.None)
reader.OpenInputDevice()
reader.OpenOutputDevice()
End Sub
Shane
modified 21-Jul-17 7:43am.
|
|
|
|
|
Please edit your question and show us where the exception occurs.
|
|
|
|
|
Do you have an Item selected inside the Combobox (cbbSportIdentDevices.SelectedItem) ?
What do you see by using the Debugger (in case of exeption) ?
|
|
|
|
|
Hi Ralf
Yes I select a Com port. For my current scenario it happens to be COM5. Its weird that it all works perfectly in C#, but in my project, when I have converted to VB, it gives this exception.
|
|
|
|
|
Hi Shane,
I never thought that you assign a Com-Port at this place.
So ... there are some Information missing to go further.
How is ReaderDeviceInfo declared ?
How and where do you have the COM-Port in your code ? Where do you assign an initialize it ?
I think that are parts which belong to the Designer-Scripts from the C#-Project - you should look also there and perhaps complete your code.
If not try to answer my questions ...
|
|
|
|
|
Perhaps little background will help as I can't post an image of the form. I have an RFID reader which connects to the computer via a usb. The sample app from the supplier (the c# Code). Just provides a list of available devices in a combobox after clicking the refresh button. This all works in my VB code as well and after clicking the button it shows a list of (COM1 and COM5 on my laptop) in the combobox. After selecting the correct COM from the dropdown (COM5 in my case). You then click the connect button and it is at this point that my VB code falls over, but the C# code works fine. The form is very simple, I have compared the designer code and nothing different there either. I'm just very confused as to why the VB code gives the null exception but the C# code doesn't. Yet the code is almost identical.
The writelog is just a list box which provides a log of all the steps taken and events which are initiated by the reader.
Hope this helps
Regards
Shane
|
|
|
|
|