Between TH-cam 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 🙏🏻
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.
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 TH-cam tutorials. Thanks!
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!
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.
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!
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.
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.
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.
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.
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
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!
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.
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.
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.
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.
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.
@@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.
@@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
@@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?
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.
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.
@@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.
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.
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): th-cam.com/video/Yj69cWEG_Yo/w-d-xo.html
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.
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.
@@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.
Thank you IAmTimCorey! I was wondering. Can we execute a store procedure rather than write down our query? For example: Datable g = access.getPeople();
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.
what are the ways to learn C# and web development ? I was thinking about this question a lot. How to know c# well like other proffesionals, .. how they achieve that ? What's the path? (I saw roadmap here :D github[dot]com/MoienTajik/AspNetCore-Developer-Roadmap) I started learning c# in college at September 2019. I read a book basics of c#, done some exercises, went through a udemy course (intermediate, advanced C# with Mosh) and now I'm getting to Events in C#. I bought a book called Mastering C# (Michael B. White) and I was really boring. I knew 70% of everything written there, no detailed information. - I think books are good for getting know about what's going on with the language - It's explaining how something works. - Tutorials are great for practise and they explain how something should be done. - And there are platforms for training the problem solving. (Codewars) But still I don't know a good effective resources. Could you give us some pieces of advice about How to learn C#, the path of developer, what books are needed to read to get understand how C# works (C# via CLR, maybe?). Should I learn .NET Framework or focus on new .net Core? Where are a good resources ? I would like to be a good web developer, that means I should learn C#, LINQ, Design principles, .NET core 3.1, Blazor, SQL lang + platforms, CSS, a little bit of JS framework (Vue should be the easiest), code refactoring and then I would be ready to start producing some nice web apps ! but how to achieve that? - read books (which ones please ?) - go through some tutorials/courses (probably udemy, yt, etc.?) - practise what I learn (make a small website?) What an intermediate developer should go through to become a pro like you ? How to jump up to the next level ? thank you all for reading this and thinking about it. I would be really happy to get some replies from you.
This is the place to start for all C# developers: th-cam.com/video/LUv20QxXjfw/w-d-xo.html I'll be covering more in my upcoming Dev Questions series soon.
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.
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?
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.
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 ?
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!
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.
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
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?
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
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
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.
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?
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.
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?
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
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.
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
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.
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.)
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.
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.
@@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
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.
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.
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?
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
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.
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: th-cam.com/video/24iujm49y10/w-d-xo.html
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.
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.
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
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.
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.
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.
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?
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?
I do have quite a few videos on Azure in some form or another: th-cam.com/users/IAmTimCoreysearch?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.
Hi sir, I have a windowsforms app build with C#, it connects with a MySql database to store and retrieve data, I use Mysql.data for that, it actually runs on local host where the database exists too. But every time I need the app, I need to run XAMPP first so that I can connect to the database. Is there a way to connect to the database directly from the app without using any extra software? Thanks for your great content 💙
@@IAmTimCorey Thanks for your replay sir 🌹 What I mean is: now, my customer needs to install XAMPP in addition to the software I wrote, and every time he reboots his system, he needs to deal with an extra program -wich is XAMPP again- which kinda doesn't make sense for him.. Is there a way to create and run a MySql server with my C# code (maybe a library or a custom package) so that I don't need to use an external software? Thanks again 🌹
I have the same problem. When I use _config.GetConnectionString("default") the connectionstring is empty. If I wrote ist manually the connection is established. And it is named default.
@@mazharpatel784 I just ignored the _config... line and replaced it with the final string: string constring = "Server=127.0.0.1;Database=mydatabase;User ID=mydbuser;Password=123;SslMode=none"; await _data.SaveData(sql, new { NPeople = "Max", PPeople= "Mustermann" }, constring); So there is no call to the config anymore.
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?
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: th-cam.com/video/eKkh5Xm0OlU/w-d-xo.html
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.
How can I read input elements value updated by user. How to reference it in SQL update query. You have entered actual value in SQL while executing update.
How you get data from the user is a different video (in fact, I have done videos like that a number of times). Once you get the data, you put it in place of my placeholder data.
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.
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.
@@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
Severity Code Description Project File Line Suppression State Error Project '..\DataLibrary\DataLibrary.csproj' targets 'net8.0-ios17.2'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v8.0'.
It looks like you used an iOS class library (probably MAUI) rather than a standard .NET 8 class library. That is why you cannot reference it. You would need to change it to be a standard .NET 8 class library.
@@IAmTimCorey Hi thank you for replying to me. After taking a very good look at everything you did I figured out i could choose what version of the things you installed. So i download the exact version of the items you had and it fixed everything. The newer versions does not work. Your video help me well though. Thank you
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.
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.
Between TH-cam 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 🙏🏻
I am glad my content has been so helpful.
I truly agree with you here.
i realize it is pretty randomly asking but do anybody know of a good place to stream new series online ?
@Joseph Lewis try Flixzone. Just search on google for it =)
@Archer Samson yup, I have been using flixzone for since march myself :)
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.
I am glad it was helpful.
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 TH-cam tutorials. Thanks!
Thank you!
Totally agree, Tim never fails to accurately explain topics without leaving you confused
Thanks for the video, I had looked at other tutorials but none of them worked, until I found your channel.
I am glad it was so helpful.
It's my favorite kind of tutorial: focused, not overbearing and contains new information. I like dapper and blazor server 😊
Glad you enjoy it!
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!
You are welcome.
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.
Glad it helped.
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!
I am glad it was helpful.
been looking for a while on a lot of places and this one was the most helpful and straight video i found. Thanks!
Excellent!
Awesome tutorial, very simple & sweet language
Successfully created demo by watching this video without any error or bug
Thank you so much
Thanks for growing your skills with this video.
Wonderful video from which I learned so much. Thank you Tim Corey for your effort!
You are welcome.
Thank you, very helpful video, 29:36 - you can wait for it like this List rows = (await connection.QueryAsync(sql,parameters)).ToList();
Yep. I just find it easier to separate it into two steps because it makes debugging easier.
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.
Glad it helped!
Keep up the good work you're amazing! I can't seem to get my head around C# until I discovered your channel!
Welcome aboard!
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.
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.
Simply Amazing !!!! I use the same steps to connect my application to the Oracle database. Hats off !!!
Great 👍
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.
I am glad you figured it out.
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
Thanks for sharing! I hope Dapper works better for you
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.
You are welcome.
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!
Maybe that will come in a complete application series.
Exactly what I needed. Thank You very much!
Thanks for looking to Tim when you need help skilling up!
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.
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.
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.
You are very welcome
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.
Thanks, added to the topics list.
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.
Thanks for sharing.
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.
@@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.
timy u c sharp legend lol thanks alot
You are welcome.
Thank you for sharing the knowledge and doing it so well.
My pleasure!
Really helpful video. Thanks!
You're welcome!
First: scheduled to watch tomorrow early morning. NZ thx in advance Tim.
You are welcome.
Thanks bro i have learned alot.
Glad to hear it.
I loved your tutorial.
Thanks!
@@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
@@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?
Superb as always Tim :)
Thanks!
I felt the temptation, but you went for that Interface, nice.
Glad you enjoyed it.
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.
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.
@@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.
Thanks, just what I needed.
Glad I could help!
I love you tim.. You help a lot.
Thanks
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.
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): th-cam.com/video/Yj69cWEG_Yo/w-d-xo.html
Many thanks sir!
You are welcome.
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.
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.
in the new vs2022 version is no startup.cs. where do i need to add the services? in program.cs it won' work
It will work in Program.cs. Here is a video on how to do it: th-cam.com/video/vdhFw1VSowg/w-d-xo.html
@@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.
Thank you IAmTimCorey! I was wondering. Can we execute a store procedure rather than write down our query?
For example:
Datable g = access.getPeople();
Thank you Tim
You are welcome.
thank you, Tim
You are welcome.
Just a newbie question. Does this method not prone to cyber-attacks like SQL Injection?
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.
@@IAmTimCorey I see. Thank you. I am learning a lot from you.
Yes this is what I'm looking for
Glad to hear it.
YOU SAVE LIFES
Thanks!
Hi Tim cory! i want you to talk about cross cutting and Aspect oriented prgramming with c#, how to handle it, best practices, thanks
Thanks for the suggestion.
@@IAmTimCorey thanks i hope you will consider my request
wow a 3 years old tutorial that still works
👍
what are the ways to learn C# and web development ?
I was thinking about this question a lot. How to know c# well like other proffesionals, .. how they achieve that ? What's the path? (I saw roadmap here :D github[dot]com/MoienTajik/AspNetCore-Developer-Roadmap)
I started learning c# in college at September 2019. I read a book basics of c#, done some exercises, went through a udemy course (intermediate, advanced C# with Mosh) and now I'm getting to Events in C#. I bought a book called Mastering C# (Michael B. White) and I was really boring. I knew 70% of everything written there, no detailed information.
- I think books are good for getting know about what's going on with the language - It's explaining how something works.
- Tutorials are great for practise and they explain how something should be done.
- And there are platforms for training the problem solving. (Codewars)
But still I don't know a good effective resources. Could you give us some pieces of advice about How to learn C#, the path of developer, what books are needed to read to get understand how C# works (C# via CLR, maybe?). Should I learn .NET Framework or focus on new .net Core?
Where are a good resources ?
I would like to be a good web developer, that means I should learn C#, LINQ, Design principles, .NET core 3.1, Blazor, SQL lang + platforms, CSS, a little bit of JS framework (Vue should be the easiest), code refactoring and then I would be ready to start producing some nice web apps !
but how to achieve that?
- read books (which ones please ?)
- go through some tutorials/courses (probably udemy, yt, etc.?)
- practise what I learn (make a small website?)
What an intermediate developer should go through to become a pro like you ? How to jump up to the next level ?
thank you all for reading this and thinking about it. I would be really happy to get some replies from you.
This is the place to start for all C# developers: th-cam.com/video/LUv20QxXjfw/w-d-xo.html I'll be covering more in my upcoming Dev Questions series soon.
@@IAmTimCorey thank you! i didn't know about this video!
Very useful thank you 🙏
You are welcome.
Hi
Tim, thx for the video. Two questions, why not use ToListAsync() in LoadData ? It's because the overhead that come with async/await?
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.
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?
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.
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 ?
Hey! I couldn't find startup.cs file in my latest BlazorServer app. Can you help how to do Dependency injection at 21:27?
Here you go: th-cam.com/video/vdhFw1VSowg/w-d-xo.html
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!
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.
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
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?
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
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
Mobile is different because the connection string cannot be private, so you will need to use an API.
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.
Hi Tim, I watched other video of yours and got wiser by them. I see that this video was created 4 years ago. Do you think it is still current today?
There will be slight differences, but most of the code will be exactly the same today.
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?
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.
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?
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
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.
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
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.
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.)
th-cam.com/video/8DNgdphLvag/w-d-xo.html this helped me - i dont know where the difference is, but well it works ;)
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.
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.
@@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
Very informative. How about a tutorial on MongoDB.
Here you go: th-cam.com/video/69WBy4MHYUw/w-d-xo.html
@@IAmTimCorey thanks
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.
Why have two ORMs? Use Dapper for both.
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.
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?
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
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.
@@IAmTimCorey Thank you. You are completely correct is is NET 6 and Server.
Hi Tim!! Is there a course on your website for MySQL and C#? More specifically MVC?
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: th-cam.com/video/24iujm49y10/w-d-xo.html
Does this approach works with Blazor Web Assembly app and a MySQL database locally hosted on xampp ?
No, it’s still a web application. That wouldn’t be secure.
Hi Tim, great content, off course!
In Blazor we don't use controller or "code behind" like razor pages?
Blazor uses the MVVM pattern.
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.
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.
how to solve this problem at connectionString ?
error : The option 'IntegratedSecurity' is not currently supported.
You would need to remove the unsupported parameter. You can use this site to help you form a proper connection string: www.connectionstrings.com/
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
Check out the TimCo Retail Manager series. In it, we implement dependency injection in our API once we upgrade it to .NET Core.
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.
I will add that suggestion to the list. Thanks.
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.
Sounds like you have an issue on your machine. This isn't normal behavior.
@@IAmTimCorey This intermittent issue occurs only when I try to update data. Read data always works fine.
It sounds like you have something in place that is closing your connection to the database. Use breakpoints and track it down.
Hi Tim... When trying to add a new page, I don't have the choice for Razer components.. what do I need to do??
Sorry... Tim I found it.. I had to add item to get to the Component.
I am glad you found it.
Thanks a lot buddy :)
You are welcome.
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.
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?
SQL and Oracle are equally good at security. I'll add your suggestions to the list.
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?
You would put an API in between.
@@IAmTimCorey Thanks!
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.
You could do that with Blazor and some monitoring of the database, yes.
Great video!,
I have a trivial question, how can I send an explicit long query string with JOIN etc.? , thanks
Just like you would with a select statement. I do not believe there is a length limit on your query.
Hi Tim, Thanks for you Videos.
Awesome
Do you have video about Authorized?
Not specifically, but see if these add value - th-cam.com/users/IAmTimCoreysearch?query=authent
@Tim when u will going to put up some cloud videos(aws or azure) ..is it on ur list in this year?
I do have quite a few videos on Azure in some form or another: th-cam.com/users/IAmTimCoreysearch?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.
Hi sir, I have a windowsforms app build with C#, it connects with a MySql database to store and retrieve data, I use Mysql.data for that, it actually runs on local host where the database exists too. But every time I need the app, I need to run XAMPP first so that I can connect to the database. Is there a way to connect to the database directly from the app without using any extra software?
Thanks for your great content 💙
As long as your MySQL server is still running, you can connect to it directly, like I did, instead of having all of XAMPP running.
@@IAmTimCorey Thanks for your replay sir 🌹
What I mean is: now, my customer needs to install XAMPP in addition to the software I wrote, and every time he reboots his system, he needs to deal with an extra program -wich is XAMPP again- which kinda doesn't make sense for him..
Is there a way to create and run a MySql server with my C# code (maybe a library or a custom package) so that I don't need to use an external software?
Thanks again 🌹
Not MySQL, no, but check out SQLite. It can be self-contained rather than needing a database engine to power it.
@@IAmTimCorey Thanks a lot 🌹
May I ask what software you use to screenshot/zoom in and edit?
Tim did a video on this. th-cam.com/video/PJGSTLwl2nA/w-d-xo.html
Specifically, I use Zoom It by SysInternals: docs.microsoft.com/en-us/sysinternals/
_config.GetConnectionString("default")
It won't send me the String back. Anyone knows why?
Maybe it isn't named default?
I have the same problem. When I use _config.GetConnectionString("default") the connectionstring is empty. If I wrote ist manually the connection is established.
And it is named default.
@@prodematrix268 please can you elaborate what to be done. Even I am facing connection string problem while performing insert and update.
@@mazharpatel784 I just ignored the _config... line and replaced it with the final string:
string constring = "Server=127.0.0.1;Database=mydatabase;User ID=mydbuser;Password=123;SslMode=none";
await _data.SaveData(sql, new { NPeople = "Max", PPeople= "Mustermann" }, constring);
So there is no call to the config anymore.
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?
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.
@@IAmTimCorey gotcha. Thanks for the reply!
How would you get the last inserted id when you add something to the database with dapper?
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: th-cam.com/video/eKkh5Xm0OlU/w-d-xo.html
Great videos and very practical. Would you have an example using Blazor+Dapper+Oracle?
I don't yet, no.
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.
Yep, you could do that.
How can I read input elements value updated by user. How to reference it in SQL update query. You have entered actual value in SQL while executing update.
How you get data from the user is a different video (in fact, I have done videos like that a number of times). Once you get the data, you put it in place of my placeholder data.
@@IAmTimCorey If you have a video on this , please can you give me the link.
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.
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.
@@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
Can this DataAccess method be applied when using WinFroms?
Yep.
What is the mod / extension you are using to auto complete using statements?
That's just Visual Studio. No mods or extensions.
@@IAmTimCorey Thank you. I must have missed a setting. Still new to this.
Hello I love your video but i need help.I'm getting errors. stuff like DataLibrary not compatible.
I am using DotNet 8.0
Severity Code Description Project File Line Suppression State
Error Project '..\DataLibrary\DataLibrary.csproj' targets 'net8.0-ios17.2'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v8.0'.
It looks like you used an iOS class library (probably MAUI) rather than a standard .NET 8 class library. That is why you cannot reference it. You would need to change it to be a standard .NET 8 class library.
@@IAmTimCorey Hi thank you for replying to me. After taking a very good look at everything you did I figured out i could choose what version of the things you installed. So i download the exact version of the items you had and it fixed everything. The newer versions does not work. Your video help me well though. Thank you
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.
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.
is this video series include client server (API) sample project version?
What video series? This is a stand-alone video covering MySQL in Blazor Server.