|
Next up, on the Server Roles tab, which roles have checkmarks next to them?
|
|
|
|
|
Public & SysAdmin
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
OK, based on your answers, the login should work.
I would go back to SQL Server Manager and create a new SQL account, password, and permissions of dbcreator and public. Change your connection string and remove TrustedConnection and put in the username and password of the account you create.
|
|
|
|
|
That's what I thought too.
I have created a new login and still get the same error. Here's my Conn string
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionString = @"Server=MAROIS_KEVIN_1\SQLEXPRESS;Database=Test;User Id=FatALbert;Password=AlbertIsFat!;;Encrypt=false;";
optionsBuilder.UseSqlServer(connectionString, options => options.EnableRetryOnFailure());
}
and the exception
Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException
HResult=0x80131500
Message=The maximum number of retries (6) was exceeded while executing database operations with 'SqlServerRetryingExecutionStrategy'. See the inner exception for the most recent failure.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation[TState,TResult](Func`3 operation, Func`3 verifySucceeded, TState state)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Program.<Main>$(String[] args) in C:\Projects\SandBox\Learning\EF6Core\Database First\EFCoreDBFirstExample\Program.cs:line 11
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
SqlException: Cannot open database "Test" requested by the login. The login failed.
Login failed for user 'FatAlbert'.
I also tried creating the DB 'Test' first in SQL and assigning it to FatAlbert and the same exception.
Again, I have other apps running on my Dev PC that don't use SQL Authentication and they connect just fine. So I has to be something with EF.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Wait a minute. Did you put the connection string ONLY in the OnConfiguring method?
|
|
|
|
|
Yes. The examples I followed show it there. Isn't that what OnConfiguring does? A one time set up?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
This works differently from the older Entity Frameworks. The reason you're getting the login failure is because the database does not exist in SQLEXPRESS yet.
You cannot create the database just by running the code you have, as is. You first have to enable migrations in the project, then create your first migration ("InitialCreate"). Once that is done, you can add the following line your program:
using (var db = new ModelContext())
{
db.Database.Migrate();
var newDept = new Departments();
newDept.DepartmentId = 1;
newDept.DepartmentName = "Development";
I highly recommend AGAINST doing this! You are far better off managing and applying migrations using the EF command line tools! You can EASILY make a mistake that will destroy a production database just by running your code at the wrong time and with the wrong connection string!
Migrations Overview - EF Core | Microsoft Learn[^]
On top of that, there's a few mistakes in your code in your initial post above. For example, every DbSet should be DbSet<type> ...
public virtual DbSet<Department> Departments { get; set; }
public virtual DbSet<Employee> Employees { get; set; }
...and there are mispellings in your modelBuilder code, like
entity.ToTable("Employees", "public");
|
|
|
|
|
Thanks alot!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
OK, so I went through the Migrations Oerview and installed the necessary packages. I then ran Add Migration and Update Database. Now I get this
Applying migration '20221127185110_Initial'.
Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
IF SCHEMA_ID(N'public') IS NULL EXEC(N'CREATE SCHEMA [public];');
Microsoft.Data.SqlClient.SqlException (0x80131904): There is already an object named 'public' in the database.
CREATE SCHEMA failed due to previous errors.
at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean isAsync, Int32 timeout, Boolean asyncWrite)
at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:5f3126d9-a1c8-4a81-b0f8-8eba5fd77448
Error Number:2714,State:6,Class:16
There is already an object named 'public' in the database.
CREATE SCHEMA failed due to previous errors.
Set Rant On
This is why I have stayed with Linq-To-SQL. EF is WAAAAAY too complicated. The fact the I need to run console commands is mind-boggling. There's no UI for this? Point & click! And the amount of learning and work to set it up is astounding. And god forbid you make a mistake.
Set Rant Off
Ok, so I'm not even sure what 'public' it thinks is in the DB. It created the DB but not any tables with the exception of MigrationsHistory. So I'm now back where I started - stuck. Any idea what 'public' it's referring to?
Also, do you know of any references that can walk me through setting up & using EF Core. Assume I know nothing. I have this book. I went through the entire first chapter where he sets up the tables, relations, and DBContext, and there's no mention of Migration so far.
Thanks again.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 27-Nov-22 14:55pm.
|
|
|
|
|
Change "public" to "dbo" in your code.
Where did you find this tutorial you're following?
The problem with Linq-To-Sql is that it is a dead product and no longer under development.
|
|
|
|
|
Dave Kreskowiak wrote: Where did you find this tutorial you're following?
I have the book I mentioned in my other reply, as well as a couple of YouTube vids I followed.
Dave Kreskowiak wrote: The problem with Linq-To-Sql is that it is a dead product and no longer under development.
Yup. Thats why I'm doing this.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
OK, I think I have this now.
I did the migration and update, and the DB was created and Department and Employee tables added.
Next, I added a Companies entity, linked it to Departments, and ran
dotnet ef migrations add AddCompanies
dotnet ef database update
and the Db is now up to date.
So I need to run these 2 commands each time I make a change?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Yes.
You can make a ton of changes and wrap them all in a single migration. Open the migration file and take a look at what's generated.
|
|
|
|
|
OK, I get it now.
That book I referenced doesn't show any of this, so far. Now I get why nothing was happening when I ran my console app. I was under the impression that creating the DBContext would do all of this
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
In a production environment, you would NEVER hardcode a connection string. This would prevent you from developing against a dev version of the database and testing code and migrations without impacting the production database.
Read the entire section on Migrations, not just the Overview:
Migrations Overview - EF Core | Microsoft Learn[^]
|
|
|
|
|
Ya, I Put it there just for testing.
Thanks for all your help
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Have you checked the file permissions for the database? I suppose that for a Trusted Connection that is not relevant.
Can you open the database using that connection string in SSMS, or VS I suppose?
modified 24-Nov-22 17:59pm.
|
|
|
|
|
No I didn't check.
There is no DB. EF is supposed to create ut
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hello.
Can someone help me with source codes on how to append a QRCode to an already existing PDF file located somewhere in a folder. I have tried but its clearing the available content on the already existing PDF file. I dont want it to clear. I just want it to append the QRCode to the existing content on the existing PDF File.
//GeneratedPdf generatedPDF = new GeneratedPdf();
Document document = new Document();
string path = @"C:\Setups\To Process\";
string originalFileName = "myTestPDFFile.pdf";
PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream(path + originalFileName,
FileMode.Append));
document.Open();
string strBarCodeValue = "https://mytest.com/my-Portal/invoiceChk.htm?
actionCode=loadPage&invoiceNo=0885434";
BarcodeQRCode barcodeQRCode = new BarcodeQRCode(strBarCodeValue, 120, 120, null);
document.Add(barcodeQRCode.GetImage());
document.Close();
|
|
|
|
|
Fezih5 wrote:
PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream(path + originalFileName, FileMode.Append)); That simply appends a brand new PDF file to the end of the original file. The result will not be a valid PDF file.
You need to read the existing PDF file into memory, and then modify it.
The documentation for the Java iText library, on which iTextSharp is based, has this example:
Chapter 5: Manipulating an existing PDF document[^]
Hopefully the libraries won't have diverged too much, so you should be able to work out how to translate that to the iTextSharp version.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello someone help me to find a C# program that counts the numbers of triangles in a Graph
thanks so much.
|
|
|
|
|
We're not a Google service for you. You 're perfectly capable of "finding" your own results.
The problem with your question is what do you mean by "counts the number of triangles in a Graph." What's a "graph" in your app? How is the data represented?
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?
That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!
Just saying "counts the numbers of triangles in a Graph" means nothing to us without context: and even if it did, there are other problems:
1) We aren't here to do your homework
2) Your teacher is almost certainly aware of sites like this, and handing in code you "found on the internet" as your own work is called plagiarism: and the punishment for that can include expulsion from your school. Even if it doesn't, unless you write your own code, you won't learn how to - which means you will fail your final exams. Think about it: you can watch as much Tour de France as you want - it still won't teach you how to ride a bicycle!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You should be able to figure it out from the data if you understand what the "markers" represent; e.g. daily hi / lo.
If you don't understand what the markers represent, counting them is pointless.
"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
|
|
|
|
|
Hi,
I am trying to insert into sql from Dynamic object ,
But insert failed with date type values,
Can some one suggest how can I handle this situation please.
command.CommandText = "INSERT INTO table VALUES (" + "'" + string.Join("',' ", ((IDictionary<string, object="">)rec).Values) + "')";
here are object variable dates I am passing
[4] {31/05/2022 23:00:00 +00:00} object {System.DateTimeOffset}
[11] "2022-10-25 16:12:27" object {string}
|
|
|
|
|