SQL CLR - Base-64 字符数组或字符串的长度无效
SQL CLR - Invalid length for a Base-64 char array or string
我已经创建并执行了用户定义的函数。它 returns 以下错误消息。需要您的支持。
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlBoolean SqlFunctValidateUserCred()
{
bool verify = Crypto.VerifyHashedPassword("test", "test1");
return verify;
}
}
错误:
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. 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.Web.Helpers.Crypto.VerifyHashedPassword
:
Parameters
hashedPassword
Type: System.String
The previously-computed RFC 2898 hash value as a base-64-encoded string.
阅读。
您可以尝试以下操作:
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();
}
}
我已经创建并执行了用户定义的函数。它 returns 以下错误消息。需要您的支持。
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlBoolean SqlFunctValidateUserCred()
{
bool verify = Crypto.VerifyHashedPassword("test", "test1");
return verify;
}
}
错误:
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. 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.Web.Helpers.Crypto.VerifyHashedPassword
:
Parameters
hashedPassword
Type: System.String
The previously-computed RFC 2898 hash value as a base-64-encoded string.
阅读。
您可以尝试以下操作:
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();
}
}