|
Thanks so much Dave. I knew there had to be away, just couldn't find it. Vb.net is just a hobby for me but if I can help someone else I will pay this forward.
|
|
|
|
|
First some background. 10+ years ago my spouse started a small webshop and I made the administration part in Delphi. Slowly transitioning it to the web. I have tried to make everything as automatic as I can. Like register a payment automatically makes a record in the ledger.
On the same line I later made a C# .NET as a part in the handling of incoming invoices. She scans the invoice to PDF and place it on the desktop or drops it there if it is delivered electronically. My application detects the file and pops up and she can fill in the things needed to put in the ledger and store it in the database.
Now last week the application starts and then closes without being touched for years. It worked last month, the delphi written things still works.
Does anyone have any idea why, this coincide with me reading something about Microsoft removing some old version of TLS. The application uses Entityframework.
Then I tried opening up the source in VS 2017 community edition(?) where it was written but I never get past the "credentials is wrong" page. Moved the code to another computer with VS 2022 on it where I had trouble getting it to work. When I did I got back an exception telling me "opening of table didn't work" but no indication of why.
|
|
|
|
|
You've said a lot but nothing that can be used to give any suggestions. We know nothing about the code, what it uses or does, nor the EXACT exception messages.
|
|
|
|
|
I don't use C# on a daily basis and I haven't touched the code for a long time. There could be that this debug session broke when imported in 2022 instead of 2017 where the original development was done.
I hoped that someone would say something along the lines of (Microsoft disabled Tech Z version X, try installing Y). But anyway Entity framework and under references MySql.Data and MySql.Data.Entity.EF6.
NuGet packages MySql.Data 6.9.9 and MySql.Data.Entity 6.9.9 (This one is marked as depreceted).
This is the exception I received:
System.Data.Entity.Core.EntityException
HResult=0x80131501
Message=The underlying provider failed on Open.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<getresults>b__5()
at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<system.collections.generic.ienumerable<t>.GetEnumerator>b__0()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at BusinessLayer.Supplier.GetAll() in C:\mitt\marieshopnet\BusinessLayer\Supplier.cs:line 33
at PendingLedgerEvidence.Form1..ctor() in C:\mitt\marieshopnet\PendingLedgerEvidence\Form1.cs:line 60
at PendingLedgerEvidence.Program.Main() in C:\mitt\marieshopnet\PendingLedgerEvidence\Program.cs:line 19
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
MySqlException: Unable to connect to any of the specified MySQL hosts.
|
|
|
|
|
The "provider" exception (probably) refers to the MySQL database driver / adapter. If you haven't touched stuff "in years", you need to verify all the versions (of components) you need are in "sync".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Your app's connector could not connect to the database host, or it connected and failed authentication. TLS is a transport protocol, a newer version of handshaking or validating in more detail. TLS last I checked is at V1.3, and V1.0, V1.1 was discontinued, but that was years ago.
If your database is hosted at home or in your shop, then that's a local connection, and could be a firewall blocking a port number for MySQL. If your using a cloud host, then perhaps they upgraded.
But if you wrote the app personally, you should remember how that part works, and be able to fix it fairly quickly. EF has nothing to do with the connection to the database server. You can use Fiddler to watch the connection, or check error logs, there is something out there that will guide you.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
|
|
Smells like a spam setup to me. His profile lists his company name, who according to Google are "a Microsoft's Consulting having expertise in technologies like Power BI ...".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, I didn't check that.
|
|
|
|
|
This sounds suspiciously like a question you find on a certification test, for BI. You know, the very thing your company says you're supposed to be an expert in.
We're not here to do your homework for you.
|
|
|
|
|
Consensus view is that he/she is a spammer.
|
|
|
|
|
YASH PATEL 2023 wrote: How can Power BI development services assist businesses in transforming raw data into meaningful insights and visualizations?
Answer: It cannot.
But people can. They might or might not use that.
|
|
|
|
|
Here's my Program.cs file (I've actually simplified it to some extent).
using StudentsMinimalApi;
using StudentsMinimalApi.Validation;
using System.Collections.Concurrent;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.AddProblemDetails();
WebApplication app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler();
}
app.UseStatusCodePages();
ConcurrentDictionary<string, Student> _students = new();
RouteGroupBuilder studentsApi = app.MapGroup("/student");
studentsApi.MapGet("/", () => _students);
RouteGroupBuilder studentsApiWithValidation = studentsApi
.MapGroup("/");
studentsApiWithValidation.MapGet("/{id}", (string id) =>
_students.TryGetValue(id, out var student)
? TypedResults.Ok(student)
: Results.Problem(statusCode: 404));
studentsApiWithValidation.MapPost("/{id}", (Student student, string id) =>
_students.TryAdd(id, student)
? TypedResults.Created($"/student/{id}", student)
: Results.ValidationProblem(new Dictionary<string, string[]>
{
{ "id", new[] { "A student with the given id already exists." } }
}));
app.Run();
public partial class Program { }
As you can see, I created an example minimal API that exposes endpoints that you can use to access or change data related to an example Student class using the HTTP protocol.
So now I'd like to test my minimal API using xUnit. That's how I decided to test if the post method successfully creates a new student.
[Fact]
public async Task MapPost_Should_Successfully_Create_A_New_Student()
{
await using var application = new WebApplicationFactory<Program>();
using HttpClient? client = application.CreateClient();
HttpResponseMessage? resultFromPost = await client.PostAsJsonAsync("/student/s1", new Student("X", "Y", "Z"));
HttpResponseMessage? resultFromGet = await client.GetAsync("/student/s1");
Assert.Equal(HttpStatusCode.Created, resultFromPost.StatusCode);
Assert.Equal(HttpStatusCode.OK, resultFromGet.StatusCode);
string? contentAsString = await resultFromGet.Content.ReadAsStringAsync();
var contentAsStudentObject =
JsonConvert.DeserializeObject<Student>(contentAsString);
Assert.Equal(HttpStatusCode.Created, resultFromPost.StatusCode);
Assert.Equal(HttpStatusCode.OK, resultFromGet.StatusCode);
Assert.NotNull(contentAsStudentObject);
Assert.Equal("X", contentAsStudentObject.FirstName);
Assert.Equal("Y", contentAsStudentObject.LastName);
Assert.Equal("Z", contentAsStudentObject.FavouriteSubject);
}
May I ask you if this way of testing is adequate? For the testing of the post method I've actually used the get method. This does not seem like a good approach, but I don't see how else I can handle the situation. So I can't compe up with another alternative that's maybe better than this. Is there a way for me to access the _students dictionary from the Program.cs file? How would you write your tests in this situation? Thank you in advance!
|
|
|
|
|
You might want to research 'code coverage' tools. Those collect stats during your test to make sure that you have tested all code paths.
Also note that you should not be actually testing the dictionary. But rather the usage of that. But perhaps that is what you mean.
Nikol Dimitrova 2023 wrote: Is there a way for me to access the _students dictionary from the Program.cs file?
Presumably to test that the state is as excepted. Yes there are several.
1. Just publicly expose the dictionary (getter)
2. You can use reflection to get to the internals of a class.
If you use the second then you should document with a comment that it only public for testing.
For a small case like this I would use the first (getter). For larger libraries I would use reflection because the idiom is clearer with more usage and because more chance of public methods getting misused over time.
|
|
|
|
|
Thank you for the response!
May I ask you how exactly can we access the dictionary after let's say we add a student with a POST request using reflection? We can also check if the count (the number of elements of the dictionary) is correct (if we add one student, it should be 1; if we add 2 students, then it should be 2, and so on).
I couldn't achieve that because we are actually using a WebApplicationBuilder<program>.
What is the approach?
Also, if I use the first method, how exactly do I expose it with a getter? I guess I cannot use the top-level statements syntax then, because we cannot define properties in namespaces.
Thanks!
|
|
|
|
|
I had one QA type tell us we "had to" test every "if" and "else". And this was a "budgeting" system.
There's a concept of "good enough" for the task (that QA can't deal with).
I just have a "feeling" you've gone too far when you start asserting strings beyond "required" / not required. Checking the contents of fields is the job of "edit / validation" programs.
(Which probably answers why we don't need to test "everything" as per QA).
A "good design" (IMO) just requires fewer unit tests.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
This is my first time trying to to print directly to a printer using the PrintDialog and PrintDocument. I thought it would be like creating a PDF, where I just compose and create a file and print, but it looks like I'm forced to use an event handler to compose my print document using Drawing.
I was on the internet, and the examples where very simple and basic, but my document is going to be huge, and used many times in my c# winforms .Net Core 7 app. So I used ChatGPT to help me design a class, that I can call as my event handler, but I'm missing something in my class, or got it wrong on how all of this works.
On my Print Dialog Form, when I hit the print button, my code example ...
The printDefault.Question is what I'm trying to call, where Question is where I'm stumped ..
if (result == DialogResult.OK)
{
this.PrintObject.PrintSettings.DefaultPrinter = printDialog.PrinterSettings.PrinterName;
if (this.PrintObject.PrintSettings.DefaultDocument != null)
{
var printDefault = new PrintDefault
{
Bol = this.PrintBol
};
printDocument.PrintPage += new PrintPageEventHandler(printDefault.Question);
printDocument.Print();
this.PrintComplete = true;
}
}
And my class ....
I figured that my class is an extension of PrintDocument, but I'm not sure. One of the dumb requirements is that I need the MongoDb collection document to generate the BOL form to print, because that has all my data I need to populate the document I'm trying to create. I'm not really sure if my design is sound or not, and may have to think of an alternative. But I feel like I'm really close, just missing something that I didn't think of.
namespace SimpleBol.Classes.DirectPrint
{
public class PrintDefault : PrintDocument
{
public BILLOFLADINGS Bol { get; set; } = null!;
public void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
Font fontTitleBold = new Font("Arial", 16, FontStyle.Bold);
Font fontTitleRegular = new Font("Arial", 16, FontStyle.Regular);
Font fontLargeBold = new Font("Arial", 12, FontStyle.Bold);
Font fontLargeRegular = new Font("Arial", 12, FontStyle.Regular);
Font fontMedium = new Font("Arial", 10);
Font fontSmall = new Font("Arial", 8);
Font fontTiny = new Font("Arial", 6, FontStyle.Italic);
SolidBrush brush = new SolidBrush(System.Drawing.Color.Black);
RectangleF printArea = e.PageSettings.PrintableArea;
if (e.Graphics != null)
{
SizeF textSize = e.Graphics.MeasureString("BILL OF LADING", fontTitleBold);
float x = printArea.Left + (printArea.Width - textSize.Width) / 2;
float y = printArea.Top + (printArea.Height - textSize.Height) / 2;
e.Graphics.DrawString("Date: ", fontMedium, brush, x, y);
if (Bol != null)
{
string date = Bol.BolDate.ToString("dd-MM-yyyy");
e.Graphics.DrawString("Date: " + date, fontMedium, brush, x, y);
e.Graphics.DrawString("Shipper: " + Bol.ShipperName, fontMedium, brush, x, y + 20);
e.Graphics.DrawString("Vendor: " + Bol.ShipFromVendor, fontMedium, brush, x, y + 40);
}
}
}
protected override void OnPrintPage(PrintPageEventArgs e)
{
base.OnPrintPage(e);
PrintDocument_PrintPage(this, e);
}
}
}
On another note; since this is my first time, what's the best way to test during document composition. I threw out my cheap printer with cheap toner, and can't see having to print a sheet a paper on every test. Should I build a temp print preview first, and get it close enough there, and then use paper to fine tune?
Now I'm wondering if I should change my print dialog to show the preview first, and then hit the print button. The downside to being a rogue programmer is that I have no team to ask for help, and any help or opinions would be appreciated.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I can't help you with the print class, but I do have an idea about the testing.
Do you have MS Office installed on your development machine? If so, I believe that also installs a "Print to PDF" printer driver. You could use that to print to a PDF file instead of the printer.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I didn't think of that! I have CutePDF that I print all my orders with, before I email them.
Thanks!
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
On top of that, ChatGPT should not be used to write code. It sucks at writing anything beyond "Hello World" and WILL lead you down incorrect paths.
|
|
|
|
|
I'm beginning to realize that now.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I'd like to put all of my custom classes into a .NET Framework DLL so that I can share them among many different executables.
If I install a NuGet package to the DLL, are the classes in that package supposed to be available to any EXE that holds a reference to the DLL?
Or NuGet packages can't be shared that way, meaning the package must be installed to the EXE, not the shared library?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
In my experience, NuGet packages are on a project basis (dll; exe), though you can manage them at the solution and project level.
You can "share" a dll's Nuget package via the dll as an "interface"; otherwise, I know of no way to surface "name spaces" from a dll other than the one it "owns".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Thanks for the response, Gerry. Can you elaborate on what you mean by sharing the package as an interface? Do you mean I'd have to write code (interfaces) that specifically expose the types in the NuGet package?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|