Hello everyone I'm trying to manually create a new user in my table but impossible to generate a "UniqueIdentifier" type without threw an exception ...

大家好,我正在尝试手工在我的表中创建一个新用户,但是不可能不抛出一个异常就生成一个“惟一标识符”类型……

Here is my example:

这是我的例子:

DECLARE @id uniqueidentifier
SET @id = NEWID()

INSERT INTO [dbo].[aspnet_Users]
           ([ApplicationId]
           ,[UserId]
           ,[UserName]
           ,[LoweredUserName]
           ,[LastName]
           ,[FirstName]
           ,[IsAnonymous]
           ,[LastActivityDate]
           ,[Culture])
     VALUES
           ('ARMS'
           ,@id
           ,'Admin'
           ,'admin'
           ,'lastname'
           ,'firstname'
           ,0
           ,'2013-01-01 00:00:00'
           ,'en')
GO

Trow exception -> Msg 8169, Level 16, State 2, Line 4 Failed to convert a character string to uniqueidentifier.

Trow异常-> Msg 8169,级别16,状态2,第4行未能将字符字符串转换为惟一标识符。

I use the NEWID() method but it's not work...

我使用NEWID()方法,但它不工作……

http://www.dailycoding.com/Posts/generate_new_guid_uniqueidentifier_in_sql_server.aspx

http://www.dailycoding.com/Posts/generate_new_guid_uniqueidentifier_in_sql_server.aspx

2 个解决方案

#1


27

ApplicationId must be of type UniqueIdentifier. Your code works fine if you do:

应用程序id必须是类型标识符。如果您这样做,您的代码可以正常工作:

DECLARE @TTEST TABLE
(
  TEST UNIQUEIDENTIFIER
)

DECLARE @UNIQUEX UNIQUEIDENTIFIER
SET @UNIQUEX = NEWID();

INSERT INTO @TTEST
(TEST)
VALUES
(@UNIQUEX);

SELECT * FROM @TTEST

Therefore I would say it is safe to assume that ApplicationId is not the correct data type.

因此,我认为,假定ApplicationId不是正确的数据类型是安全的。

更多相关文章

  1. SHOW STATUS 查看各种类型SQL执行的频率
  2. 类型不敏感的nvarchar类型的主键,其中ß!= ss
  3. SQL Server CLR函数类型不匹配。
  4. SQL Server 中 存储“经纬度”应设置的数据类型
  5. 每条sql语句实际上都是一个事物(事物多种类型解读)
  6. Java向MySQL数据库插入时间类型Date数据时需要注意的问题
  7. MySQL入门很简单: 2 MySQL数据类型
  8. Mysql 修改字段类型
  9. Ms sql 2005 中的bit 数据类型

随机推荐

  1. 获取Android版本信息和电话信息
  2. android listView实现单选
  3. android触屏手势识别全解析
  4. Android 获取系统权限的代码
  5. Difference of px, dp, dip and sp in an
  6. CheckBox自定义
  7. android给view比如layout等添加阴影效果
  8. ScrollView嵌套RecyclerView冲突解决
  9. Android(安卓)Intent调用大全
  10. Android(安卓)binder 原理及实现机制