Project Question Summary 2:guid is it case-sensitive?

Source: Internet
Author: User

Problem Description:

Recently in the process of doing the project, encountered a problem, will be from the basic system query out the course ID as a parameter to evaluate the system to check the examination information, but what also can not find out, debugging for half a day do not know what the reason.


Problem Analysis:calm down to think about, you can be sure that the program code logic and implementation is not a problem, so is the problem of data. Then the data problem should be a database problem, in the process of single-step debugging, to check the values of variables and parameters, and finally found out where the problem, first to see the two systems of the database storage CourseID data type is what it, such as:
The left is the base, and the right is the exam. Take a look at how my code implements the process described in the description of the problem:
If you think about it, you realize a question, what is the GUID?? so Baidu a bit: the globally unique identifier (guid,globally unique Identifier) is also known as the UUID (universally unique Identifier). A GUID is a numeric identifier generated by the algorithm with a binary length of 128 bits. GUIDs are primarily used in networks or systems that have multiple nodes, multiple computers. Ideally, no computer or computer cluster will generate two identical GUIDs. The total number of GUIDs reaches 2^128 (3.4x10^38), so the probability of randomly generating two identical GUIDs is very small, but not 0. The term GUID also sometimes refers to Microsoft's implementation of the UUID standard. People are digital identifiers good, distinguish what size! Alas, less reading! No, we can use code to verify:
//Verify GUID case-sensitive GUID g1 = new GUID ("6D025D37-A957-44B1-9E25-50D6BFD            57a39 ");            GUID g2 = new GUID ("6d025d37-a957-44b1-9e25-50d6bfd57a39"); Console.WriteLine (G1.                   Equals (G2));  Returns True Console.WriteLine (Object.referenceequals (G1, G2)); return false//Use the ToString function to convert the GUID to string type, observing their value string strg1 = G1.            ToString (); String strg2 = G2.            ToString (); Console. WriteLine (STRG1.  Equals (STRG2));            Returns True Console.WriteLine (STRG1);            Console.WriteLine (STRG2);            But if your database storage type is varchar, it's not the same. String str1 = "6d025d37-a957-44b1-9e25-50d6bfd57a39";            String str2 = "6d025d37-a957-44b1-9e25-50d6bfd57a39"; Console.WriteLine (str1.  Equals (STR2)); Returns false Console.read (); 
and the uniqueidentifier mentioned earlier , is the GUID in the database storage type, they are actually a thing. In this way, there is a lot of clarity.
Problem Solving:There are two ways: one is to keep the data types of the two databases consistent, which is the fundamental solution; If you do not want to modify the database, you can then use the varchar data type to store the GUID string, but to ensure that it must be in the letter lowercase format, Otherwise, when querying based on its field values, the string cannot match the string produced by the ToString () method of the GUID, so the query result is definitely incorrect, and the recommended or uniform data type.
Summary:In fact, think carefully or the basic things are not solid, I do not know the concept of GUIDs, so there will be the title of the questions described. If I know for sure that the GUID is a binary-length 128-bit numeric identifier generated by the algorithm, then it might be quick to find out where the problem is.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Project Question Summary 2:guid is it case-sensitive?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.