Can someone help me? I got this error
Hi, so i have table
Laporan_Penilaian
form another database
. When i tried to run my project i got this error. My suspect because failed connection to other database?62 Replies
that just means it couldnt find a table with such name
failed connection to database would throw a different error
Idk why it cant find, i mean the table name is right...
can you show the table?
sure
this
thats just a sql command, did u even run it?
does the table even exist?
the tbale exist
table*
can u show where it exists?
this is the table, sorry only can show this there's sensitive data
maybe ur connecting to the wrong database
Is that affect if i have table Laporan_Penilaian but i named my model LaporanPenilaian?
I connected to the right database
This is my connection string. Default for db1 and log for db2 (the table laporan_penilain exist). Maybe am i wrong here?
show code where u are trying to access the table
this one(?)
anyway i g2g, check the connection string
okay
Are you sure you're connection to both dbs?
I’m not sure actually I’m connecting to db2
Kuo you’re
How are you connecting to the databases
I mean i write my server and database name here.
Yeah, these are your connection string, how are you using EF to do the actual connection using these strings?
Emm i followed the tutorial. Not sure how to connect double database in EF. Db1 succeed connect to EF.
Okay, in
ConfigureServices
how are you adding DbContext?This is my RepositoryContext
Do you have a call like this
services.AddDbContext<T>(....)
in ConfigureServices
in Startup.cs
?You have to create a 2nd context probably to connect to a 2nd db
No i can't find this
I wouldn't advise mixing them into one context
Ah so you mean 2 repositorycontext?
Control + Shift + F and look for
AddDbContext
Why is your data in two different databases?It's default from there
Okay i will try to create 2nd context, thanks
You'll need to add the other context using
AddDbContext
How to this?😅 I look for Ctrl + shift +
AddDbContext
but i don't understandWhat guide did you use for EF, ?
Press
Ctrl + Shift + F
and select Entire solution from the dropdown menuand search
AddDbContext
this one, yes?
yes you want to duplicate this for your new context
you probably want to name the contexts a bit better so it's clear which data is where
for example
ProductContext
and CustomerContext
if the data is in different DBs
but is there no way you can merge the data in one db? Makes it a lot easierAdding to Tvde1's answer, make sure to change the connection string
for you new context
Okay i already duplicate that and change the name connection string, what's next?
No it's impossible to merger data in one db cause it's actually the database already running in another project too
You consume that context like you'd normally do
And i added new dbcontext file, but it still has same error 😅
Did you change the type when duplicating
AddDbContext
?yes Kou i change it to
MappiEgovContext
too
Wait maybe i should try to the default one. Only change this oneYeah, make sure you have changed all instances
This is right, right? But i still get same error 😅
is Cache:Enable true? Then you also have to add a DbContextPool for the new context
The type is wrong 😅
it should be
MappiEgovContext
ah yes that too
OMG i missed
It's not working😵 Should i change this to MappiEgovContext? But if i changed it, repositoryContext error
yes you should change it there
what is the error you get?
this
your repository base needs to be updated :)
maybe add a generic type of the repository itself
Can i just duplicate this?
I would make it
but this is best for you to figure out how to best add this into your software
Hey thank you so much finally i can connect to my db2. i never expected i need to change so many file too. Thanks again😊