Showing posts with label Microsoft. Show all posts
Showing posts with label Microsoft. Show all posts

Monday, March 18, 2024

ModelState.Clear vs TryValidateModel(manageModel)

 


`ModelState.Clear()` and `TryValidateModel(manageModel)` are both methods commonly used in ASP.NET Core applications to manage model validation.

1. `ModelState.Clear()`: This method is used to clear any model state errors that have been added to the `ModelState` dictionary. In ASP.NET Core, `ModelState` is a dictionary-like object that holds information about the state of model binding and validation for a given request. It stores information about model properties and their validation errors. Calling `ModelState.Clear()` removes all existing validation errors, effectively resetting the model state to a clean state.

2. `TryValidateModel(manageModel)`: This method is used to manually trigger model validation for a specified model object (`manageModel` in this case). By calling `TryValidateModel(manageModel)`, you are instructing ASP.NET Core to validate the specified model object against any validation rules defined in its associated data annotations or custom validation logic. If validation succeeds, the method returns `true`, indicating that the model is valid. If validation fails, the method returns `false`, and any validation errors are added to the `ModelState` dictionary.

In summary, `ModelState.Clear()` is used to clear any existing model state errors, while `TryValidateModel(manageModel)` is used to manually trigger model validation for a specific model object. These methods are often used together to ensure that model validation is performed correctly in ASP.NET Core applications.

Monday, May 10, 2021

Windows 10 Your Phone

Just found Windows 10’s Your Phone app on my $300 ThinkPad Yoga book, which I really like. The App links your android phone with PC. Of course it works with iPhone but it's said it works best for Android users, letting you text from your PC, sync your notifications, and wirelessly transfer photos back and forth, also screen your phone to TV.

OK, Sounds pretty good, usually I USB connect my Huawei Pro20 with PC to transfer files, specially pictures and songs. So with Phone app we can do those wirelessly, WIRELESSLY, yes, nowadays it's a very popular thing.

Setup Your Phone is extremely easy, just click Windows Logo on your PC and scroll down the bottom, click it and follow along, I made a silly video, you can watch if you like to support my starting YouTube Channel. 

Also a quick tip about the Windows OneDrive, OneDrive is Microsoft's cloud storage for consumers, and it is built into Windows 10. For free, it comes with 15 GB of storage, and there are a couple of paid tiers to increase that storage. 15GB is plenty for normal people:), but make sure you are aware of the OneDrive sync options.

The OneDrive cloud icon in the Windows taskbar notification area, right click it will show some options/tasks you can do.  I also added a little talk about this on the below clip.

Well, let's leave our phones somewhere and focus on the PC:))




Thursday, August 6, 2009

TSQL - Job Failed (sp_addlinkedsrvlogin)

Hey, last time I just mentioned we are working on MS SharePoint stuff, so SQL server and T-SQL, all familar stuff...uh...

I learned database stuff through T-SQL at school, since our school has a good deal with MS, which school deesn't have? I have to admire MS's business strategy (sarcastic? I don't think so:)

So Our T-SQL team has a procedure to get data from oracle database and insert data into SQL table using OpenQuery, the procedure is working fine on local, but it failed when they put it as SQL job. The team jsut asked me to help so after quite some tries, we found the error is caused by invalid login. The log error is long and confusing, talking about expected NT user failed to login.

Then the problem is narrow down to the sp_addlinkedsrvlogin (Transact-SQL). There are 2 logins, local and remote login. The procedure uses some real account such as SA and some other accounts created for local login. The server is set up to use Windows and SQL loin option. Since I just jump in to try to help the team, I just trouble shooting from my experience without knowing all the set up in servers.

From MSDN:
[ @locallogin = ] 'locallogin'
Is a login on the local server. locallogin is sysname, with a default of NULL. NULL specifies that this entry applies to all local logins that connect to rmtsrvname. If not NULL, locallogin can be a SQL Server login or a Windows login. The Windows login must have been granted access to SQL Server either directly, or through its membership in a Windows group granted access.

after reading this, I tried to use NULL for local login, and it worked! I am not sure how to use actual local login to make it work on SQL job. I may check on this if I have time, or if the team has interest on that... And it's working, most time we are just lazy to explore more... hehe.

So I put this on net, hopefully someone has same situation and might be helpful. Long live sharing knowledge!