[英]SQL CLR - Invalid length for a Base-64 char array or string
I've created a user defined function and executed. 我创建了一个用户定义的函数并执行了。 It returns the below error message.
它返回以下错误消息。 Need your support.
需要您的支持。
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlBoolean SqlFunctValidateUserCred()
{
bool verify = Crypto.VerifyHashedPassword("test", "test1");
return verify;
}
}
Error: 错误:
Msg 6522, Level 16, State 2, Line 11 A .NET Framework error occurred during execution of user-defined routine or aggregate "SqlFunctValidateUserCred": System.FormatException: Invalid length for a Base-64 char array or string.
消息6522,级别16,状态2,行11在执行用户定义的例程或聚合“ SqlFunctValidateUserCred”时发生.NET Framework错误:System.FormatException:Base-64字符数组或字符串的长度无效。 System.FormatException: at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength) at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)
System.FormatException:at System.Convert.FromBase64_Decode(Char * startInputPtr,Int32 inputLength,Byte * startDestPtr,Int32 destLength)at System.Convert.FromBase64CharPtr(Char * inputPtr,Int32 inputLength)
at System.Convert.FromBase64String(String s) at System.Web.Helpers.Crypto.VerifyHashedPassword(String hashedPassword, String password) at UserDefinedFunctions.SqlFunctValidateUserCred()在System.Convert.FromBase64String(String)在System.Web.Helpers.Crypto.VerifyHashedPassword(String hashedPassword,字符串密码)在UserDefinedFunctions.SqlFunctValidateUserCred()
System.Web.Helpers.Crypto.VerifyHashedPassword
: System.Web.Helpers.Crypto.VerifyHashedPassword
:
Parameters
参数
hashedPasswordhashedPassword
Type: System.String类型:System.String
The previously-computed RFC 2898 hash value as a base-64-encoded string .先前计算的RFC 2898哈希值, 以base-64编码的string 。
Read. 读。
You can try following : 您可以尝试以下操作:
public static void AddUsersToDatabase(string databaseserver, string databasename, string usertobeadded)
{
using (SqlConnection conn =
new SqlConnection("server=" + databaseserver +
"; database=" + databasename +
"; User ID=WPDOMAIN\\spdev; Integrated Security=SSPI; password=Password123;"))
{
conn.Open();
string password = "Password123";
string sql = "CREATE LOGIN " + usertobeadded + " WITH PASSWORD = '" +
password + "'; USE " + databasename + "; CREATE USER " + usertobeadded + " FOR LOGIN " + usertobeadded + ";";
SqlCommand cmd = new SqlCommand(sql);
cmd.ExecuteNonQuery();
conn.Close();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.