|
This is over my head, and I don't know c#. But when I deal with forms and tables, I tend to use .Visible=false on individual elements to hide them, yet have the data still exist to be referenced later. Not sure it can help you
|
|
|
|
|
The conventions don't understand that you wanted UserId to be the foreign-key column for the ApplicationUser navigation property.
As a result, EF assumes that UserId is just a standard string column, which is not connected to anything. It added the ApplicationUser_Id column to serve as the foreign-key link for the ApplicationUser navigation property.
Code First Conventions - EF6 | Microsoft Docs[^]
For the conventions to work, you'd either need to rename the UserId property to ApplicationUserId , or rename the ApplicationUser property to User .
If you can't rename either property, you need to use data annotations or the fluent API to configure your foreign key relationship correctly. For example:
[Required]
[Index("IX_UniqueConstraintCaseAssignedToInvestigator", 2, IsUnique = true)]
[MaxLength (128)]
[ForeignKey(nameof(ApplicationUser))]
public string UserId { get; set; }
public ApplicationUser ApplicationUser { get; set; } Or:
modelBuilder.Entity<CaseAssignedToInvestigator>()
.HasOne(case => case.ApplicationUser)
.WithMany()
.HasForeignKey(case => case.UserId);
Code First Data Annotations - EF6 | Microsoft Docs[^]
Fluent API - Relationships - EF6 | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
For VB.net 2008
So a program i've had in my head for a while, i've been thinking about how to go about retrieving data over the internet or even lan (securely)
mysql is a possibility, but dealing with the cert files on the client and lack of support for the connector is a pain (mainly due to no longer support for .net 2008, and I plan to make it strict .net 3.5 for compatability reasons)
What I did with one old, unrelated program was (.net 2005) was use PHP to feed XML over https (though it had no signing, I overrode that). This seemed to work fine, but i'm still not sure if this is the BEST way to go about it.
Really I think of the best ways would be PHP/MySQL/XML over lan, but I don't want to expose my scripts
any other ideas?
|
|
|
|
|
A "LAN" is not the same things as "the internet" in terms of a target audience.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
oh believe me I know.
But network (lan) traffic can still be intercepted, packet sniffed, and if unencrypted, exploited.
I'm now looking into possibly mysql over SSH. Disadvantage of course is the app must have the SSH username/password as program variables, which can be extracted. Vs direct MySQL, which you can just have a person login with their own mysql username and password. Is there any way to disassociate SSH with the filesystem/console and just mysql
is there any better way than using XML/SSH for over the internet (yes, not lan). As i'm still not sure if I should do this lan or internet.
This is a computer repair management software, i'm going to initially write it for myself, and maybe later release it, i'm not sure free or pay. If I use an internet web connector, I can enable a payment system for peoples accounts, but if thier internet is out, they can't use it. Lan, they can.
i'm also considering using studio 2012, as the mysql connector does not work in 2008 (says "system cannot find the reference specified")
and as much as i've learned vb.net a few years back, c#.net seems to be closer to PHP, my long learned language. Might consider learning c#
|
|
|
|
|
Hi. I want to implement a sending email service using .net core worker service. For doing that I use .net core 3 Worker service and in Worker class and I added NetCore.MailKit 2.0.2 to my project. I added the below lines of code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Mail;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic;
using MimeKit;
using MimeKit.Text;
namespace MyWorkerService
{
public class Worker : BackgroundService
{
private readonly ILogger<worker> _logger;
private HttpClient client;
public Worker(ILogger<worker> logger)
{
_logger = logger;
}
public override async Task StartAsync(CancellationToken cancellationToken)
{
var message = new MimeMessage();
message.To.Add(new MailboxAddress("Mike", "mike@gmail.com"));
message.From.Add(new MailboxAddress("Elen", "elen@gmail.com"));
message.Subject = "Hi";
message.Body = new TextPart(TextFormat.Html)
{
Text = "Email for testing"
};
//-----------------------------------------------------------
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Connect("smtp.gmail.com", 587, false);
//SMTP server authentication if needed
client.Authenticate("elen@gmail.com", "fava");
client.Send(message);
client.Disconnect(true);
}
}
public override async Task StopAsync(CancellationToken cancellationToken)
{
// DO YOUR STUFF HERE
await base.StopAsync(cancellationToken);
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(1000, stoppingToken);
}
}
}
}
And the program class is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace MyWorkerService
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseWindowsService()
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<worker>();
});
}
}
I could created and deployed the service and when I start it, its status changes to running. Now my problem is, it doesn't send any email to the specified email address. I appreciate if anyone could solve my issue.
|
|
|
|
|
First, debug it and make sure the code works as is. Secondly, add logging so you can see what is happening.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Google is quite restrictive on the use of its SMTP server. Use your debugger to check exactly what happens inside the sending method.
|
|
|
|
|
NB: I hope that's not your real GMail username and password that you've just posted to a public forum?
If it is, you should change your password immediately, and review your account for any suspicious activity.
But I would hope that Google wouldn't let you use such an insecure password.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hey Guys,
I'm just trying my first steps in Entity Framework. My Database is a Maria with Version 10.4.x.
For connecting to DBMS I setup a Project with the EF6.
References:
- EntityFramework
- MySql.Data
- mysql.data.entity.EF6
- MySql.Data.EntityFramework
All versions are the newest Version of NUGET. (Working on VS2019)
When I want to generate the Data-Model (ADO.NET Entity Data Model) through the Project-Explorer, I get an Error:
"The Project references latest Version of EntityFramework; for Connection a compatible (for this version) Entity Framework-Databasedriver could not be found."
It seems to me that there is something missing... but what? Is there still a libirary missing?
Regards
|
|
|
|
|
|
Excel.Application oExcel = new Excel.Application();
oExcel.Visible = true;
Excel.Workbooks oWorkbooks = oExcel.Workbooks;
string Pfad = "C:\test.xlsx";
Excel.Workbook oWorkbook = oWorkbooks.Open(Pfad);
Excel.Worksheet oSheet = oWorkbook.Sheets[1];
oSheet.Cells[1, 1] = "Test";
oSheet.SaveAs("C:\test.xlsx");
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.FinalReleaseComObject(oSheet);
oWorkbook.Close();
Marshal.FinalReleaseComObject(oWorkbook);
oExcel.Workbooks.Close();
Marshal.FinalReleaseComObject(oWorkbooks);
oExcel.Application.Quit();
Marshal.FinalReleaseComObject(oExcel);
oExcel = null;
Above code is not working on server. Office is not activated on server so this is reason to not closing it or any other issue, please help me to solve this problem
|
|
|
|
|
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
There are various ways to create or modify Excel spreadsheets on the server without using Office interop. For example:
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello experienced people!!
I want to convert a data from text file to IList of X,Y,Z coordinates.
Actually i need to create topography in Autodesk Revit which needs Ilist of X,Y,Z coordinates. the text file which i am having i can manually directly feed into Revit and create topography as its X,Y,Z Coordinates. But using by c# coding in visual studio i need to convert it to Ilist of X,Y,Z coordinates to be ready as an input. Below is the text of my text file which is X,Y,Z separated by commas
609608.949,5641208.924,309
609609.283,5641208.227,309
609609.793,5641207.702,309
609610.469,5641206.828,309
609610.809,5641206.479,309
609611.318,5641205.954,309
609611.821,5641205.083,309
609612.496,5641204.212,309
609612.996,5641203.342,309
609613.664,5641202.299,309
609613.991,5641201.433,309
609614.149,5641200.741,309
609614.476,5641199.875,309
609614.637,5641199.357,309
609614.963,5641198.492,309
609615.115,5641197.630,309
609615.440,5641196.767,309
609615.596,5641196.077,309
609616.251,5641194.697,308.983
609616.407,5641194.008,308.977
609616.723,5641192.805,308.965
609617.043,5641191.946,308.952
609617.198,5641191.432,308.947
609617.508,5641190.232,308.935
609617.658,5641189.376,308.929
609617.812,5641188.691,308.923
Also i used this code line to access all lines of this text file as strings
List<string> lines = File.ReadAllLines(@"D:\My.txt").ToList();
|
|
|
|
|
The quick and dirty way is to loop over each line, do a string split using the comma and then convert the values from strings. Alternatively, you could use one of the many CSV libraries to read and parse the lines.
|
|
|
|
|
can you explain a little more as i am new to coding, can you five a little example
|
|
|
|
|
|
I am not sure the subject gives a clear indication of my problem/question.
I am building a set of applications based on a common database. In order to facilitate this I have a VB.NET project that handles all of the database connectivity and manages the tables.
One class in this project "Functionality" has methods for the actual database calls. The connection string is fixed in it.
The other classes in this project are for each table in the database for save, loadrecord, etc. Each of these classes instantiates the Functionality class to select/insert/update.
This project is compiled into a dll.
Other projects which include a stand-alone programme to deal with repetitive tasks and a desktop application, reference the DLL and instantiate the tables classes as required to obtain data, and change it.
Move forward and I now need the entire system to work with a second database. However the database is identical in structure. So the only change is the connectionstring. Obviously I can change this in the Functionality class, recompile the DLL. And recompile the applications and I have a version working with the new database. However, what I want is to be able to switch between the databases on the fly. And this is my problem.
I need someway for the Functionality class to be able know which Database (M or T or A or S) is required by the application that instantiated a table class that is using the Functionality class.
So, the Desktop application can have a Public Shared variable, but this can not be seen by the called method of the table class.
If you understand this, is there anyway of doing what I want?
|
|
|
|
|
Store the connection string in the application's configuration file, and have the "functionality" class read it from there.
Eg:
="1.0"="utf-8"
<configuration>
<connectionStrings>
<add
name="Functionality"
connectionString="........."
providerName="System.Data.SqlClient"
/>
</connectionStrings>
</configuration>
Private Shared Function CreateConnection() As SqlConnection
Dim connectionString As String = ConfigurationManager.ConnectionStrings("Functionality").ConnectionString
Return New SqlConnection(connectionString)
End Function If you need to access more than one database in a single application, you'll need to modify your classes so that you can pass in the connection string name somehow. You can still read the actual connection string from the configuration file.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for answering. However, it didn't answer the question it told me something I knew - which is why I had the problem.
What it did do is highlight that there isn't an answer, which is what I thought.
|
|
|
|
|
Use an "interface".
You can have a static that references an interface (of an object) that you set at runtime to your primary database class from the appropriate Dll (i.e. the "repository").
Windows, in a number of cases, has a "Current" static that references the "app", "main window", etc. The same holds true for your app if you "know" there can only be ONE active repository, or weigh scale, or whatever.
If you already have 2 "database" dlls, I assume there are 2 namespaces; the interface goes into a different namespace from the previous 2 for it to "work".
(and maybe it's just the "connection" component you put in a separate dll and interface (if you want it hard-coded); the rest of the db code can be in the same name space if it's shareable).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
modified 28-Jan-20 11:00am.
|
|
|
|
|
Thank you. Whilst I am not sure I would use an Interface to achieve what I need to do, you have helped me solve my problem.
Using Process I can see the main window's title from the instantiated class, because it is in the myprocess. As long as I have what I need there I can do it. It would be nice to be able to create a property on the process that I could see as easy to see it would be great.
Dim pReturn As Process
pReturn = Process.GetCurrentProcess()
cKey = (Left(pReturn.MainWindowTitle, 3)
All that is needed is a Select Case and I can change to the appropriate connection string for the company using the programme.
Thanks again.
|
|
|
|
|
I would not rely on the Main Window Title; any application can pretend to be your target.
If you can find the proces, then you can find the executable that is being executed. At that point, you can load that assembly and query its assembly-attributes.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I need to set this source code on my new project. You can see my project and give me the reviews about it.
|
|
|
|
|
What you are asking about is the Data Access Layer (DAL - use this for your Google Foo). There are many articles and examples about this available.
As Richard said pass in your connection string, remember you need to move from development DB to production DB at some time!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|