Тёмный

Connecting C# To MySQL Using Blazor (Full CRUD Actions) 

IAmTimCorey
Подписаться 417 тыс.
Просмотров 85 тыс.
50% 1

How do I talk to MySQL from C#? That's a pretty common question. MySQL databases are very popular, especially on the web. So when you are building a web application especially, you might be considering using MySQL. Fortunately, there is a very easy way to connect to MySQL databases using C# and in this video, I am going to show you how to do just that.
Mailing List: signup.iamtimcorey.com
Source Code: leadmagnets.app/?Resource=Con...
Purchase Courses: iamtimcorey.com
0:00 - Intro
0:51 - Demo Blazor Server App
3:57 - Adding a Class Library
5:43 - Adding NuGet packages
7:04 - Data Access class:
8:27 - • Load data method explained
15:51 - • Save data method explained
18:20 - Library dependency
19:15 - New Blazer page
20:48 - Dependency injection (startup.cs)
24:38 - Razor page setup: Using statements
25:45 - Making data access methods Async
32:25 - Adding Data Models
34:11 - Razor Page setup: Calling data access
37:19 - MySQL Connection string
41:11 - Razor Page layout for displaying data
44:11 - Save Data
49:14 - Update Data
52:40 - Delete Data
54:55 - Summary and concluding remarks
Thanks to Ralfs HBK for the chapters breakdown

Опубликовано:

 

1 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 339   
@dickybird08
@dickybird08 4 года назад
Between RU-vid and my IAmTimCorey courses I’ve seen this process so many times... but Every time I learn a little more about constructors, classes, dapper, sql dev, using statements, mapping, etc... the understanding that this guy gives us is invaluable. This is something like khan academy for C# ... Believe it or not but you are watching one of the best parts of the internet. thank you man 🙏🏻
@IAmTimCorey
@IAmTimCorey 4 года назад
I am glad my content has been so helpful.
@hory-portier
@hory-portier 3 года назад
I truly agree with you here.
@josephlewis347
@josephlewis347 3 года назад
i realize it is pretty randomly asking but do anybody know of a good place to stream new series online ?
@archersamson254
@archersamson254 3 года назад
@Joseph Lewis try Flixzone. Just search on google for it =)
@blainetripp2951
@blainetripp2951 3 года назад
@Archer Samson yup, I have been using flixzone for since march myself :)
@manuthpemmawadu2201
@manuthpemmawadu2201 2 года назад
dude i searched the internet for so long and finally i got to the right place. Man, if any out there is watching this, dude you are at the right place. Mr. tim corey keep up the good work.
@IAmTimCorey
@IAmTimCorey 2 года назад
I am glad it was helpful.
@zoltan.halasz
@zoltan.halasz 4 года назад
It's my favorite kind of tutorial: focused, not overbearing and contains new information. I like dapper and blazor server 😊
@IAmTimCorey
@IAmTimCorey 4 года назад
Glad you enjoy it!
@HemmingEducation
@HemmingEducation Год назад
This was brilliant! I've looked at so many videos trying to figure out how to do this but yours was concise, accurate and well presented. You made it look simple to use blazor with a database which is not always the case with other RU-vid tutorials. Thanks!
@IAmTimCorey
@IAmTimCorey Год назад
Thank you!
@kristoffermg5986
@kristoffermg5986 Год назад
Totally agree, Tim never fails to accurately explain topics without leaving you confused
@johecht7872
@johecht7872 4 года назад
Big thank you from me. I needed exactly this for my project and you uploaded this video on the exact same day. I was really frustrated, that I wasn't able to find something good and then you uploaded your video.
@IAmTimCorey
@IAmTimCorey 4 года назад
Glad it helped!
@kristianrincon1576
@kristianrincon1576 Год назад
Thanks for the video, I had looked at other tutorials but none of them worked, until I found your channel.
@IAmTimCorey
@IAmTimCorey Год назад
I am glad it was so helpful.
@garethcairncross3269
@garethcairncross3269 4 года назад
This is the first of your vids I've watched and I got say we'll done! Like Einstein said: If you can't explain it simply, you don't understand it well enough. I've been struggling with this topic for a few days and your tutorial has cleared up everything for me!
@IAmTimCorey
@IAmTimCorey 4 года назад
I am glad it was helpful.
@thangpham5864
@thangpham5864 3 года назад
Keep up the good work you're amazing! I can't seem to get my head around C# until I discovered your channel!
@IAmTimCorey
@IAmTimCorey 3 года назад
Welcome aboard!
@MarcosJunior-mx6jl
@MarcosJunior-mx6jl 2 года назад
been looking for a while on a lot of places and this one was the most helpful and straight video i found. Thanks!
@IAmTimCorey
@IAmTimCorey 2 года назад
Excellent!
@bobDotJS
@bobDotJS 4 года назад
I switched from .NET to Node a few months back and fell in love with VueJs/Node/TS... But there's no way I'm not taking full advantage of this tutorial to Make myself more valuable to employers. My eyes just lit up when I saw this. Thank you Tim!
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@bohuang3122
@bohuang3122 2 года назад
Wonderful video from which I learned so much. Thank you Tim Corey for your effort!
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@hory-portier
@hory-portier 3 года назад
I just figured out how many lines of code I have needlessly written in recent months while working with MySql myself... On the other side you just saved me from wasting even more time and space in the future. I need to do some refactoring this week. Thanks.
@IAmTimCorey
@IAmTimCorey 3 года назад
Glad it helped.
@annasahebrahane5879
@annasahebrahane5879 3 года назад
Awesome tutorial, very simple & sweet language Successfully created demo by watching this video without any error or bug Thank you so much
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 года назад
Thanks for growing your skills with this video.
@alainstross3108
@alainstross3108 4 года назад
Thanks for all your video Tim, and also thank you for your clear diction. English is not my birth language therefore I can perfectly understand you.
@IAmTimCorey
@IAmTimCorey 4 года назад
You are very welcome
@w123au
@w123au 3 года назад
Simply Amazing !!!! I use the same steps to connect my application to the Oracle database. Hats off !!!
@IAmTimCorey
@IAmTimCorey 3 года назад
Great 👍
@adamv2628
@adamv2628 4 года назад
well thought through and well explained. i like it a lot and learn to see things come together at the same time. thanks for this talk.
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@X400DYL
@X400DYL 4 года назад
Superb as always Tim :)
@IAmTimCorey
@IAmTimCorey 4 года назад
Thanks!
@Bubinga
@Bubinga 4 года назад
Wow, great tutorial. I have been working/learning EF core for the past couple months. After a series of complex error messages and struggling to do even basic things, I've decided to move to Dapper finally. I should have listened to you earlier lol
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks for sharing! I hope Dapper works better for you
@bobDotJS
@bobDotJS 4 года назад
Hey Tim. I actually learned to code using your WinForms videos. I took that knowledge and learned Node & Vue and I'm launching a product in the coming weeks which is over 2,000+ hours of code deep but I consider C# and .NET to be imperative to my general 'computer science' understanding. This video has been on my 'todo' list for nostalgia's sake although I don't get to play with C# much these days, I needed a day off from my project and thought this tutorial would help me unwind. I managed to modify the code a bit and connect to my production server/database and I added appsettings.json to .gitignore. Now I have a great template for Blazor/MySQL which can be a lot of fun in the future. Blazor actually feels like a mix of React & Vue which is pretty cool because I like both. I've noticed a trend that a lot of .NET developers eventually gravitate to Angular. I'm sure as people get more comfortable with Blazor that will change but I've always wondered why .NET devs tend to gravitate to Angular. I've seen it more than a handful of times. Is it that Angular has more of an 'Enterprise' feel than it's counterparts? Just wondering your take on that.
@IAmTimCorey
@IAmTimCorey 4 года назад
I am glad my videos have been so helpful. As to why people seem to gravitate towards Angular from .NET, I'm not sure. It may be a market thing. They see Angular jobs and they start pursuing what is more prevalent to them.
@davep8695
@davep8695 4 года назад
Awesome video Tim, as always. Would love to see you take this topic a little further by using some forms for data input and data grids for displaying the data back please. Keep up the great work!
@IAmTimCorey
@IAmTimCorey 4 года назад
Maybe that will come in a complete application series.
@TwoThr3e
@TwoThr3e 2 года назад
Exactly what I needed. Thank You very much!
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 2 года назад
Thanks for looking to Tim when you need help skilling up!
@xoanxose4715
@xoanxose4715 3 года назад
Thank you for sharing the knowledge and doing it so well.
@IAmTimCorey
@IAmTimCorey 3 года назад
My pleasure!
@bhuwanmaharjan397
@bhuwanmaharjan397 4 года назад
First: scheduled to watch tomorrow early morning. NZ thx in advance Tim.
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@luismendez9436
@luismendez9436 4 года назад
Thanks, just what I needed.
@IAmTimCorey
@IAmTimCorey 4 года назад
Glad I could help!
@iuliandutu4001
@iuliandutu4001 3 года назад
Really helpful video. Thanks!
@IAmTimCorey
@IAmTimCorey 3 года назад
You're welcome!
@angkolkagaw
@angkolkagaw 3 года назад
I love you tim.. You help a lot.
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks
@zensic
@zensic 2 года назад
Many thanks sir!
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@willinton06
@willinton06 4 года назад
I felt the temptation, but you went for that Interface, nice.
@IAmTimCorey
@IAmTimCorey 4 года назад
Glad you enjoyed it.
@jankool01
@jankool01 4 года назад
I had trouble with the DELETE - permission problem. In MySQL workbench, used Edit / Preferences / SQLEditor - bottom of page uncheck 'Safe Updates (rejects UPDATES....)'. Then worked OK. You did mention in the video there could have been a problem at this point. As always, great video. Best regards. Jan.
@IAmTimCorey
@IAmTimCorey 4 года назад
I am glad you figured it out.
@mikavesasto3371
@mikavesasto3371 3 года назад
This is awesome. Thanks. :) I love the tooling MS giving us. It has everything included and core apps can be run on Linux machines, but the MS SQL Server is the only limiting factor. You can't really use it outside of Azure and it's too expensive for personal projects. The free tier isn't enough for real-world personal projects that would be alive over 12 months. MS SQL is really good and would love to use it. Especially loved how you used database projects with TimCoRetailManager. I've searched, but couldn't find any way to use that for MySQL/Postgres. The only add-on I did find was dbForge Fusion for MySQL, but it costs like a $300. Can't really afford that for personal projects.
@IAmTimCorey
@IAmTimCorey 3 года назад
Well, for personal use, you can use SQL Server Developer Edition, which is free. There is also a version of Microsoft SQL that runs on Linux. Check out this video of running SQL on Docker (on Linux): ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Yj69cWEG_Yo.html
@abdelkiki
@abdelkiki 3 года назад
Thank you Tim
@IAmTimCorey
@IAmTimCorey 3 года назад
You are welcome.
@ahmedkhudhair8035
@ahmedkhudhair8035 4 года назад
Very useful thank you 🙏
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@gavranhas
@gavranhas 2 года назад
thank you, Tim
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@amanazad4028
@amanazad4028 3 года назад
Thanks bro i have learned alot.
@IAmTimCorey
@IAmTimCorey 3 года назад
Glad to hear it.
@teemusekki1743
@teemusekki1743 3 года назад
Yes this is what I'm looking for
@IAmTimCorey
@IAmTimCorey 3 года назад
Glad to hear it.
@kandy1249
@kandy1249 3 года назад
I loved your tutorial.
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks!
@kandy1249
@kandy1249 3 года назад
@@IAmTimCorey do you have a discord server? I'm learning c#. I like this language but there's so much to learn. This tutorial really helped me when i was just searching for a connection string that would work. Is there no way to find the connection string that you need? I also realized instead of using "user id=", you can also use "uid =" I was thinking if you can use "localhost" instead of 127.0.0.1
@kandy1249
@kandy1249 3 года назад
@@IAmTimCorey also, I use linux KDE neon as my main OS. I don't have that legacy of "visual studio" as it's not yet available on linux. So i use visual studio code. Do you even have a tutorial on entity Framework? And if yes, is it linux user-friendly tutorial? Like can you do it all on visual studio using dotnet CLI? Here's a request, can we do a whole Blazor project including restful API, UI, backend, database all being done using visual studio code, dotnet CLI?
@leogarza5022
@leogarza5022 3 года назад
Thank you IAmTimCorey! I was wondering. Can we execute a store procedure rather than write down our query? For example: Datable g = access.getPeople();
@kent8695
@kent8695 Год назад
Thank you, very helpful video, 29:36 - you can wait for it like this List rows = (await connection.QueryAsync(sql,parameters)).ToList();
@IAmTimCorey
@IAmTimCorey Год назад
Yep. I just find it easier to separate it into two steps because it makes debugging easier.
@Gramr98
@Gramr98 4 года назад
0:29 "My goal isn't to entertain you. My goal is to turn you into a world-class developer" - Well, imo you manage to do both at the same time. You educate us in an entertaining way and explain very clear. Really good job. Could you also make a video how to access multiple SQL 'types' such as TSql, MySql, Sqlite in the same project without using an external framework (e.g. because you aren't allowed to), but with the default classes instead? You know, SqlConnection, MySqlConnection, DbConnction, SqlCommand, MySqlCommand, DbCommand, etc... Or if that's too much, a simple video about the Managed Extensibility Framework would help as well. I'm really stuck with that.
@IAmTimCorey
@IAmTimCorey 4 года назад
Not sure if Dapper qualifies as an "external framework" but the C# Application from Start to Finish course does something like this - it sets up both SQL data access and Text file data access and allows you to choose between the two via a toggle. I'll add your vote for MEF to the list.
@mazharpatel784
@mazharpatel784 3 года назад
Thanks for your video. Dapper seems much more easy to learn and implement than EF. Please can you also do a video showing how to display data in datagrid and how to generate Reports.
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks, added to the topics list.
@idlehands34
@idlehands34 4 года назад
Thanks a lot buddy :)
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@vmwarek1144
@vmwarek1144 3 года назад
Startup.cs Can not add services.AddSingletonDataAccess(); Or 'DataAccess' could not be found ? My Project Blazor Server .Net Core 3.1.402 Or I should Add Project Reference ?
@faicalammisaid3705
@faicalammisaid3705 2 года назад
timy u c sharp legend lol thanks alot
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@bullcarr
@bullcarr 3 года назад
You’d mentioned adding the models to the library would it be better to do that as well as have classes with methods in library for the save/load ie _data.people.savedata(person) or _data.people.update(person) ? With the sql and connection string all in the library?
@pedroferreira9234
@pedroferreira9234 4 года назад
Hi Tim, thx for the video. Two questions, why not use ToListAsync() in LoadData ? It's because the overhead that come with async/await?
@IAmTimCorey
@IAmTimCorey 4 года назад
Correct. I did not see the async to be that valuable when the data was already on the machine. This call is valuable when you have an IQueriable where the ToList actually performs the call and downloads the data.
@lloydhotchkiss7269
@lloydhotchkiss7269 3 года назад
When we publish a project with a data library what folders do we need to include on the server in order to execute the application? The publish process produces one release folder for the Data library and one for the blazor project, how does the blazor project access the data library? If you have any tutorials on migrating this to a linux vm please let me know, great video thank you for your thorough explanations.
@benjaminvitek2583
@benjaminvitek2583 3 года назад
In the other video you did "Blazor Server Side ..." you used services.AddTransient(); instead singleton like in this vid. I know the difference, but wonder what reason there might be to use one other another. P.S i use cosmos if this might change anything. And thank you very much for your vids.
@Foodies-pv7ih
@Foodies-pv7ih 4 года назад
Hi Tim cory! i want you to talk about cross cutting and Aspect oriented prgramming with c#, how to handle it, best practices, thanks
@IAmTimCorey
@IAmTimCorey 4 года назад
Thanks for the suggestion.
@Foodies-pv7ih
@Foodies-pv7ih 4 года назад
@@IAmTimCorey thanks i hope you will consider my request
@johncraig5979
@johncraig5979 4 года назад
Thanks Tim for this video. I was building a project with EfCore with clean architecture, but wanted to refacter EfCore use with interfaces... looks like I can now use Dapper for reads and EfCore for writes if I get this right.
@IAmTimCorey
@IAmTimCorey 4 года назад
Why have two ORMs? Use Dapper for both.
@johncraig5979
@johncraig5979 4 года назад
Ah, right. Noted. But that now begets how to replace a dbcontex class and a migration rub in the program class that creates the db and applies a migration upon startup of the application. I guess that might be my suggestion for another video down the road. Of. Ourse, I think I can solve this with the previous Blazir video that was a couple of months ago that showed us a IDatabase interface.
@pgnutz
@pgnutz 4 года назад
Great videos and very practical. Would you have an example using Blazor+Dapper+Oracle?
@IAmTimCorey
@IAmTimCorey 4 года назад
I don't yet, no.
@CRBarchager
@CRBarchager 4 года назад
50:00 when ever I create an update statement I always type "Update set where" and then go back and edit what ever I need for that to work. That way I never miss the 'where' and overwrite the whole table since if I was to try and run it with "update person set firstname='bob' where" the query will fail since there is not value set after where. I little tip I got from a colleague at my first developer job. Kind stuck with me and since I've taught others to do the same. I normally don't use delete that much in my day to day work but you could use that tip for delete queries aswell "delete from where" and continue from there.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thanks for sharing.
@bunkie2100
@bunkie2100 4 года назад
I’ll go you one better. I *always* write UPDATE statements as SELECT using my WHERE clause first. That way I get a visual check on the records affected by the UPDATE.
@CRBarchager
@CRBarchager 4 года назад
@@bunkie2100 I never really got the hang of it that way. I guess I just need to try it for a longer period. I see the benefits of it. I see some of my colleagues do it that way too. I have usually already made a select statement beforehand so I know the result.
@cyrildouglas9262
@cyrildouglas9262 4 года назад
Thanks Tim, even though its a demo but I still think SaveData method could be improved even more, like execute extension method from dapper returns int which is rows affected for the execution, so that I think instead of Void or Task which they are fire and forget you could use int or bool var rowsAffected = connection.Execute(..); return rowsAffected > 0; by any chance it will be great to see a video from you about CQRS as well.
@IAmTimCorey
@IAmTimCorey 4 года назад
Yep, you could do that.
@dirganaratama970
@dirganaratama970 3 года назад
Hi tim, i got a problem when add DateTime type into this tutorial project. the Date just showing default value (01/01/0001) to web page not from Database value. How to retrive date value from database (Mysql) into blazor web page?
@IAmTimCorey
@IAmTimCorey 3 года назад
You have a mismatch somewhere. Maybe your property names don't match your column names exactly. This post might help: stackoverflow.com/questions/34412224/dapper-returns-01-01-0001-000000-from-mysql-datetime
@Funkfreed
@Funkfreed 4 года назад
Excellent as always Tim. I watched the Blazor Server with SQL access tutorial as well the other day. I noticed that on that one you created an entity(or model?) for the data access library together with the sqldataaccess class. Considering that both are Blazor Server project. Which one do you think is better in terms of design? Also, when I run my app that connects to MSSQL DB it takes a long time to connect and show the list of users, I changed the access from transient to singleton hoping it would help but it didn't do much. Is this to be expected because MSSQL is not started and is being started by visual studio whenever it tries to run? If so then I think this shouldn't be a problem on a web app uploaded on cloud servers since SQL Server should always be up, am I correct in this assumption? Sorry for the long questions.
@IAmTimCorey
@IAmTimCorey 4 года назад
I am not sure what you are asking in the first question. As for the second question, it all depends on what you mean by a long time. The first time you talk to SQL, it will be a bit slower but it should not be slow. It may be because of your machine's speed or it might be a poorly-written query. I would do some investigating to figure out where the bottleneck is.
@Funkfreed
@Funkfreed 4 года назад
@@IAmTimCorey thanks I'll do that. The query is a simple select on a 5 row table. I'll try starting the sql server prior to run and see if that makes a difference
@analuisacarneiro2183
@analuisacarneiro2183 3 года назад
YOU SAVE LIFES
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks!
@zangetsu2k8
@zangetsu2k8 4 года назад
is there a good way to implement dependency injection in backend, I was halfway implementing Dependency injection in a web api controller before realizing I've never actually used dependency injection where there wasn't razor components... how does one do that? googling didn't do much for me
@IAmTimCorey
@IAmTimCorey 4 года назад
Check out the TimCo Retail Manager series. In it, we implement dependency injection in our API once we upgrade it to .NET Core.
@dirganaratama970
@dirganaratama970 3 года назад
Hi Tim, Thanks for you Videos. Awesome Do you have video about Authorized?
@IAmTimCorey
@IAmTimCorey 3 года назад
Not specifically, but see if these add value - ru-vid.comsearch?query=authent
@hfpsc27
@hfpsc27 4 года назад
Hi Tim, great content, off course! In Blazor we don't use controller or "code behind" like razor pages?
@IAmTimCorey
@IAmTimCorey 4 года назад
Blazor uses the MVVM pattern.
@ryansatchell2302
@ryansatchell2302 4 года назад
Design question: In a live scenario, would you strip all of that specific data logic(i.e. People Model, query, params, call to dataAccessor) out of the blazor page and into, for example another class Library or seperate folder within the Web project?
@IAmTimCorey
@IAmTimCorey 4 года назад
It depends on the situation. This might be the same as what I would do in production or I might add a bit more separation.
@ryansatchell2302
@ryansatchell2302 4 года назад
@@IAmTimCorey gotcha. Thanks for the reply!
@torrvic1156
@torrvic1156 Год назад
Thank you so much Mr. Corey! But I’ve got an issue. I am using .NET 6.0 (Long-term support) and I figured how to deal with Program.cs instead of missing Startup.cs but CRUD buttons are not working in a situation similar to the one you had and developer’s panel tells me that connection should be opened and valid. Thus I added connection.Open(); to methods in your library and now it works but still it gives me errors sometimes telling that another read operation is in progress or something like this. So I want to ask you if you didn’t forgot to add connection.Open(); line in your SaveData and LoadData methods of DataAccess library or maybe I am doing something wrong? Without this line it just doesn’t work at all.
@IAmTimCorey
@IAmTimCorey Год назад
At 18:10, if you look at lines 15 and 25, those lines are actually creating the connection to the database. You don't need to call open. to get this to work. If you call open, it will probably cause an issue. Also, in your case, it sounds like you are opening a connection and not closing it. That's a major issue, since that causes long-term issues for your database. I'm not sure what version of .NET this code was built upon, but this code works for all .NET versions from .NET Core 3.1 through .NET 7. So if it is having an issue, it is probably a small detail you missed.
@torrvic1156
@torrvic1156 Год назад
@@IAmTimCorey thank you for the response, sir! I found an answer to my question. Some guy in the comments had exactly the same issue and you wrote him that he need to add await instead of return in SaveData method. For some reason code does not hit the end of Using. I did like you wrote by adding await and now it works fine.
@devgenesis6436
@devgenesis6436 4 года назад
@Tim when u will going to put up some cloud videos(aws or azure) ..is it on ur list in this year?
@IAmTimCorey
@IAmTimCorey 4 года назад
I do have quite a few videos on Azure in some form or another: ru-vid.comsearch?query=azure Some of these are for Azure DevOps but I also deploy to Azure Web Apps, use Azure SQL, and set up Azure Functions.
@sunnyokoro
@sunnyokoro 4 года назад
Thanks Tim for the tutorial? How about using MySQL with EntityFramework? Can you also do a video on tht?
@IAmTimCorey
@IAmTimCorey 4 года назад
Probably not. I don't cover EF since I don't think it is nearly as useful as people think it is.
@DerlyPachecoProduccion
@DerlyPachecoProduccion Год назад
how can use in WPF this? tks.
@jackkendall6420
@jackkendall6420 4 года назад
Hi, Tim. Apologies for this not being related to the video, but what are your thoughts on doing a video about reflection? I think I get the general idea but the finer details and necessity of it somewhat escapes me. Apologies if you've already made something on the topic, I didn't find anything.
@IAmTimCorey
@IAmTimCorey 4 года назад
I will add that suggestion to the list. Thanks.
@michelchaghoury870
@michelchaghoury870 3 года назад
tnx alot for your work i am learning alot from you i want to ask you some questions. betwwen sql server and oracle sql itch one is more secured and stronger and please can you make videos about azure key vault or how to build security around dotnet application(web desk) and will you cover MAUI when it will be available and is it cross platdorm (compile it once and run the app on linx mac and windows or it will be like wpf and winform only for windows) and will you make mobile app dev in the future?
@IAmTimCorey
@IAmTimCorey 3 года назад
SQL and Oracle are equally good at security. I'll add your suggestions to the list.
@Chepaco25000
@Chepaco25000 3 года назад
Hi Tim!! Is there a course on your website for MySQL and C#? More specifically MVC?
@IAmTimCorey
@IAmTimCorey 3 года назад
I don't have a MySQL course. However, don't get too stuck on "with MVC" since the UI should not have any affect on the database used and the data access code from a Blazor Server project or WPF project should work the same in an MVC application. I cover that in more depth here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-24iujm49y10.html
@hasanpkb
@hasanpkb 3 года назад
Very informative. How about a tutorial on Sybase Central SQL Anywhere ? Have you tried to connect with Blazor? Thank you
@IAmTimCorey
@IAmTimCorey 3 года назад
I will add it to the list. Thanks for the suggestion.
@stephanmayer8576
@stephanmayer8576 Год назад
in the new vs2022 version is no startup.cs. where do i need to add the services? in program.cs it won' work
@IAmTimCorey
@IAmTimCorey Год назад
It will work in Program.cs. Here is a video on how to do it: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-vdhFw1VSowg.html
@stephanmayer8576
@stephanmayer8576 Год назад
@@IAmTimCorey hi. Thx for answering. I tried it. I wrote the services.builder.........dataaccess line in the right place, and then the blazor app don't run anymore. I can't find another reason, because, when I comment the line out, the app works.
@jvaque
@jvaque 4 года назад
A way to improve on this is to use stored procedures so you can have only certain stored procedures for different database users. But to do that with the minimum user permissions (GRANT EXECUTE ON PROCEDURE dbName.spName TO 'databaseUser'@'address';) you have to use MySqlConnector, a community MySql connector that fixes known issues in the official MySql.Data. I've been using this for my projects after I addapted the data access class from the TimCo Retail Manager and it's been working great. Also a question for Tim, I'm trying to change the database used in asp.net web apps for authentication to MySql from MSSql. I thought this might be "easy", as in change the connection string, import the necessary libraries for using MySql with entity framework, a few config changes and then let entity framework be in charge of building, modifying and queering the information as the loggin/authorization endpoints made by default that use the entity framework connection are probably more secure than what I'd be able to make. As of right now I've managed to avoid it crashing on startup of the web app but when I call the Api it fails to create the database on the first insertion (like it does when you don't have a database instantiated in MSSql). Any ideas for using entity framework with MySql? I've thought of manually creating carbon copies of the tables in the users database in MySql but don't know if there are any stored procedures/views that entity framework creates when using MSSql that it also uses.
@IAmTimCorey
@IAmTimCorey 4 года назад
My guess is that it has something to do with the data types in SQL vs MySQL but I am not sure. Working to change the Identity system can be a tricky business.
@georgevlassis8319
@georgevlassis8319 4 года назад
Suppose I have published a blazor server app to a server pc with IIS and let's suppose that this app uses two databases as you say one for the registration and the log in which will be the one created by entity and one for our data access which I will have created using an SQL server database project in Visual Studio. The question is this. Will I have to install sql server express to the server pc for this to work? If yes is there another database type I could use so I can avoid this additional installation? Thank you.
@IAmTimCorey
@IAmTimCorey 4 года назад
You use a connection string to point to where the database is located (this is true for any database type). You can have a database on a different machine from your application (and you probably should). If you wanted to use a database without installing it somewhere, SQLite is probably the right choice. Just note that it isn't the best choice for multi-user scenarios.
@pilotboba
@pilotboba 4 года назад
Nice demo. Although, all the cool kids are using MariaDB. :) Would it make more sense to handle the connection string in your injection so you don't have to deal with that in the UI code?
@IAmTimCorey
@IAmTimCorey 4 года назад
Potentially but that means you need to have a uniform way of accessing it. If some clients use IConfiguration and others don't, that would cause an issue in your class library. This way was simple and will work for any number of UIs.
@kirlisakal9645
@kirlisakal9645 Год назад
hello, is it possible to pull mobile data with this method? Is the mobile data extraction method different? I'm trying to make a mobile application, I'm new. Thank you from now
@IAmTimCorey
@IAmTimCorey Год назад
Mobile is different because the connection string cannot be private, so you will need to use an API.
@aiiqwtzhxsuenfjtd1937
@aiiqwtzhxsuenfjtd1937 2 месяца назад
I recently discovered your channel and really appreciate your work! But i had a few question relating to this section: 43:33 Why doesn't it work in blazor web assembly version? Is it because it compiles to web assembly and web assembly just can't? Also, is there any way to do it another way then? I understand that, even if it would work it woult be very bad practice (even if it WOULD work) to call the database client side, don't get me wrong.
@IAmTimCorey
@IAmTimCorey 2 месяца назад
WebAssembly runs fully on the client side. That means that the client can fully view our code. So, we cannot put any secrets in our code. That's why we don't access secure databases (just caching databases) from WebAssembly. Instead, we use APIs as an intermediary.
@Rokas108
@Rokas108 Год назад
Does this approach works with Blazor Web Assembly app and a MySQL database locally hosted on xampp ?
@IAmTimCorey
@IAmTimCorey Год назад
No, it’s still a web application. That wouldn’t be secure.
@coding_ideas
@coding_ideas Год назад
Hello Sir, thank you for this video! I am currently in the process of learning how to develop Blazor server applications and I have been able to make some progress by implementing basic CRUD operations. However, I am concerned about the security implications of passing IDs to another page without using local storage. Is there a recommended method for achieving this? , do you have any instructional videos on this topic that you can recommend?
@IAmTimCorey
@IAmTimCorey Год назад
Local storage isn't going to increase your security here. That is fully available to the client to manipulate. You need to do security checks on each page and for each action anyway, so passing IDs isn't a security risk.
@lucasmenchon8187
@lucasmenchon8187 Год назад
yo, please...how i connect with blazor webassembly ?
@megamerchannel2060
@megamerchannel2060 2 года назад
Hey Tim, I've recently started working on a project that uses blazor. So far I'm having difficulties connecting the WebApp to a local sql db. Documentation and tutorials, even this video have not enabled me to figure it out. I was wondering if you had some advice? Kind regards. Extra Info: Using .NET 6 & VS 2022 Blazor WASM + ASP.NET Core Hosting + WPA Currently in early development fase => trying to use local SQL Server (SSMS) since I've been given a replica from an existing database
@IAmTimCorey
@IAmTimCorey 2 года назад
This depends on what you mean. You can definitely connect your ASP.NET Core Hosting project to a local SQL database if that local SQL database is local to the web server that you are running on (meaning the same machine). You cannot access a local SQL database from another machine (at least not easily - you would need to open multiple firewall ports and use the IP address of the server). So if you are doing things on the same machine, just check your connection string. That's probably the problem.
@cubii8126
@cubii8126 2 года назад
how to solve this problem at connectionString ? error : The option 'IntegratedSecurity' is not currently supported.
@IAmTimCorey
@IAmTimCorey 2 года назад
You would need to remove the unsupported parameter. You can use this site to help you form a proper connection string: www.connectionstrings.com/
@euihoo
@euihoo 3 года назад
I like your video. I have a question. Can changes be displayed directly on the web as the database changes? Ask me what to do.
@IAmTimCorey
@IAmTimCorey 3 года назад
You could do that with Blazor and some monitoring of the database, yes.
@padha735
@padha735 Год назад
Hey! I couldn't find startup.cs file in my latest BlazorServer app. Can you help how to do Dependency injection at 21:27?
@IAmTimCorey
@IAmTimCorey Год назад
Here you go: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-vdhFw1VSowg.html
@leighharvey3112
@leighharvey3112 Год назад
Hi Tim. I cannot get past this error when loading the people page. "ExtendedSocketException: No connection could be made because the target machine actively refused it. 127.0.0.1:3306" I know my server is running and whatever i try it will not load. Any Ideas?
@IAmTimCorey
@IAmTimCorey Год назад
Your computer's firewall needs to have the correct ports open in order to allow that connection. Also, you say your server but unless it is on the machine that your code is also on, this won't work. The 127 IP address stands for the local machine.
@michaelangelomerza3966
@michaelangelomerza3966 2 года назад
Just a newbie question. Does this method not prone to cyber-attacks like SQL Injection?
@IAmTimCorey
@IAmTimCorey 2 года назад
That's a good thing to consider. In this case, no, it is not vulnerable to SQL injection. SQL injection is when you allow the user to impact the query string in an unsafe way. For instance, providing input that would terminate the query early and potentially run a new query such as "select * from People where FirstName='%';Drop table Person;" or something like that. In our case, we are not asking for user input so our queries cannot be manipulated like that. Also, even if we did ask for user input, we are using query parameters (the "@FirstName", etc.) This allows us to place the contents of what the user gives us into the query properly and reduces the possibilities that they can pass in code to disrupt our SQL statement. However, we should still be cautious to clean the data from the user before accepting it to be doubly certain we get good data.
@michaelangelomerza3966
@michaelangelomerza3966 2 года назад
@@IAmTimCorey I see. Thank you. I am learning a lot from you.
@logananderson2013
@logananderson2013 3 года назад
How would you get the last inserted id when you add something to the database with dapper?
@IAmTimCorey
@IAmTimCorey 3 года назад
It depends on the database, but usually you get something like Scope_Identity() (this is for SQL), etc. Then you either return that in a select statement or you return it as a output parameter. Here is an example of how to do that: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-eKkh5Xm0OlU.html
@kiembui6942
@kiembui6942 3 года назад
I am using this video to learn Dapper CRUD actions, but using a wpf .net Core application to test instead (I want to get the data layer down first). When using the connection.ExecuteAsync method I get an "Invalid operation. The connection is closed." exception. I noticed this problem goes away when I change the "using IDbConnection connection = xxx" to "IDbConnection connection = xxx" . It seems the async operation is closing the connection before the actual execution is complete. monitoring the sp_who in SQL Server Management Studio, I can see that removing the using portion of the statement does not leave any hanging open connections. Is this still dangerous practice, and is there some sort of special case with the a desktop application vs a blazor server app? Thanks for your videos they're great! edit: forgot to mention the using portion works fine for loading data, it is only the executing of queries that gives me the closed connection exception. I suspect this is because the LoadData function awaits the connection.QueryAsync and the SaveData does not await anything, just returns the task. thanks again!
@IAmTimCorey
@IAmTimCorey 3 года назад
I've not come across this issue when using async. That's odd. I agree with your hypothesis. It is concerning that the using statement is closing before it is done. I'm guessing I should have done an await on the SaveData. You will need to await the task so that it completes before the statement is closed. So if the insert takes too long (meaning it doesn't complete before the next line), it will close the connection. My code probably has the bug. The using statement should not be closed before the operation completes.
@kiembui6942
@kiembui6942 3 года назад
I see. Would you recommend structuring the methods to return Task with no using method, or changing all the methods to async voids and use the using method? Followup question for my own education, if I'm seeing no hanging connections in the SQL Management Studio what are the real dangers of not making sure to utilize the using statement? edit: I decided to play it safe regardless and just changed all of the offending methods to async voids or async tasks and added awaits and put the using statements back in
@wssDrglatze
@wssDrglatze 2 года назад
if I change from MySql.Data to System.Data.SqlClient (and the appropriate "using MySql..." statements and connection string), when "Insert", "Update", or "Delete", I get the following error: "System.InvalidOperationException: Invalid operation. The connection is closed. at system.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)". Shouldn't this work the same with sql server? (I've tried Microsoft.Data.SqlClient also.)
@wssDrglatze
@wssDrglatze 2 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-8DNgdphLvag.html this helped me - i dont know where the difference is, but well it works ;)
@almirmusanovic513
@almirmusanovic513 4 года назад
Thank you Tim. It will be so nice if you can provide an tutorial / payed course on how to deploy simple .net web app / web api but on a shared hosting like goDady...because aws / azure are so expensive..for example, i want to build an blog with custom cms..and winforms admin app...and i will buy your full timco retail manager course wery soon...but i cannot deploy my small / beginer level apps on azure...so, i am ready to pay some course on how to deploy 'timco like' apps on a shared hosting. I think that course would be awesome...
@IAmTimCorey
@IAmTimCorey 4 года назад
I will add it to the list. Thanks for the suggestion.
@lemorlenny
@lemorlenny 3 года назад
Great video!, I have a trivial question, how can I send an explicit long query string with JOIN etc.? , thanks
@IAmTimCorey
@IAmTimCorey 3 года назад
Just like you would with a select statement. I do not believe there is a length limit on your query.
@rgry
@rgry 2 года назад
I'm now at section "Dependency injection (startup.cs)" but there is no startup.cs in my BlazorServer project? Where to put the injection now? I try to put it in program.cs where the WeatherForecastService is
@IAmTimCorey
@IAmTimCorey 2 года назад
If you are using Blazor Server, it sounds like you are using the new .NET 6 Blazor Server. If you use the Blazor Server from .NET 5 you would see the Startup.cs. No worries, though, since you figured out the correct place to put the code.
@rgry
@rgry 2 года назад
@@IAmTimCorey Thank you. You are completely correct is is NET 6 and Server.
@Glip96
@Glip96 10 месяцев назад
Hi Tim. thanks to yuo i'm using dapper and loving it. I have to change a blazor server app to blazor client. Every thing wen ok until i started to connect to mysql. In server everything its ok. In blazor client the mysql driver threw an exception in any operation even when i open te connection. ¿Have you use blazor client with mysql? its that posiible?. Thans in advance
@IAmTimCorey
@IAmTimCorey 10 месяцев назад
Blazor WebAssembly runs fully on the client side. That means that your C# code goes to the client. The client can read all of your source code (this is the same way Angular, React, and Vue work). That means that we do not want to put any sensitive information in our code, including connection strings, nor do we want to give direct access to our database. That is why we use an API with any client-side application like Blazor WebAssembly or React.
@adamv2628
@adamv2628 4 года назад
you mentioned at the beginning of this video that you use Blazor server for calling mysel. as you cannot call to mysql from blazor webassembly as you said. my question is then what solution would you use to call to a backend like mysql from a blazor webassembly app?
@IAmTimCorey
@IAmTimCorey 4 года назад
You would put an API in between.
@adamv2628
@adamv2628 4 года назад
@@IAmTimCorey Thanks!
@Chris-Brown-
@Chris-Brown- Месяц назад
wow a 3 years old tutorial that still works
@IAmTimCorey
@IAmTimCorey Месяц назад
👍
@satheeshmohan
@satheeshmohan 4 года назад
Hello Tim, Can put a separate video connecting to Oracle Database Stored procedure with UDT
@IAmTimCorey
@IAmTimCorey 4 года назад
I will add it to the list. Thanks for the suggestion.
@aldotix9897
@aldotix9897 Год назад
Hey Tim, when I am going to /people like in your video, I get an exception for the IDataAccess: InvalidOperationException: Cannot provide a value for property '_data' on type 'ShoppingBot_250922.Pages.People'. There is no registered service of type 'DataLibrary.IDataAccess' Could you help me pls?
@dobiqwolf
@dobiqwolf 3 года назад
Hello Tim, Thank you for a great video, I am currently working on a project and this helped me lots however at 47:20 you mention the use of Insert Form, I am struggling with that topic and merging it with searching MySQL DB. Would you have a video that make sense on how to add the search option using insert form? I have already created the whole page using Bootstrap, I just cannot link the input text to the "where" in my "select" command.
@IAmTimCorey
@IAmTimCorey 3 года назад
To add a where clause, you would do something like this: "select * from people where LastName = @LastName" and then pass in a LastName parameter (like we passed parameters into the insert statement). You would call the LoadData instead of the SaveData though.
@dobiqwolf
@dobiqwolf 3 года назад
@@IAmTimCorey Thank you for the fast reply. My main issue is how to I get the string from the input box I created to XXXX below. people = await _data.LoadData(sql, new { LastName = XXXX }, _config.GetConnectionString("defautl")); I have been searching everywhere online but I get so many different results that I just don't understand. My inputbox code looks like this: and the button looks as below: Search
@CaGray55
@CaGray55 4 года назад
Hi Tim... When trying to add a new page, I don't have the choice for Razer components.. what do I need to do??
@CaGray55
@CaGray55 4 года назад
Sorry... Tim I found it.. I had to add item to get to the Component.
@IAmTimCorey
@IAmTimCorey 4 года назад
I am glad you found it.
@shivaakrish
@shivaakrish 2 года назад
When I try the same with .NET 6 (kestrel server) , I'm getting lots of intermittent issue saying "connection must be valid and open" and table not getting refreshed after adding/deleting/updating model.
@IAmTimCorey
@IAmTimCorey 2 года назад
Sounds like you have an issue on your machine. This isn't normal behavior.
@shivaakrish
@shivaakrish 2 года назад
@@IAmTimCorey This intermittent issue occurs only when I try to update data. Read data always works fine.
@IAmTimCorey
@IAmTimCorey 2 года назад
It sounds like you have something in place that is closing your connection to the database. Use breakpoints and track it down.
@apeters89
@apeters89 3 года назад
How do I turn on the Smart IDE that automatically adds your using statements?
@IAmTimCorey
@IAmTimCorey 3 года назад
I believe it is an option in the Tools->Options menu under Text Editor.
@rajneshp
@rajneshp 4 года назад
Very informative. How about a tutorial on MongoDB.
@IAmTimCorey
@IAmTimCorey 4 года назад
Here you go: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-69WBy4MHYUw.html
@rajneshp
@rajneshp 4 года назад
@@IAmTimCorey thanks
@hkon79man
@hkon79man Год назад
is this video series include client server (API) sample project version?
@IAmTimCorey
@IAmTimCorey Год назад
What video series? This is a stand-alone video covering MySQL in Blazor Server.
@didiksupriyadi9740
@didiksupriyadi9740 2 года назад
Awesome video Tim, How to add method return single object
@IAmTimCorey
@IAmTimCorey 2 года назад
I believe you are asking about my method that returns data from the database. Right now, it is a List. If I want to return one record, I still return a List because then I can use the same method. However, if you want to lock into returning just one item and you don't want to return a list, just create a wrapper method that makes the "normal" call and then gets the returned List and pulls out the first record (or default if none) and returns it.
@didiksupriyadi9740
@didiksupriyadi9740 2 года назад
@@IAmTimCorey Thanks for the answer, you are right, ... can i use identity asp in Blazor with dapper without EF Core?
Далее
SQL Database App with Windows GUI - Project Tutorial
3:10:25
10 C# Libraries To Save You Time And Energy
33:59
Просмотров 205 тыс.
Forget Controllers and Minimal APIs in .NET!
14:07
Просмотров 62 тыс.
ASP.NET Core Full Course For Beginners
3:43:18
Просмотров 158 тыс.
Using HttpClient in .NET Core to Connect to APIs in C#
45:03
Blazor Tutorial | CRUD With Blazor, Step By Step | .NET 7
2:26:31