oracle 密码中的特殊字符(分号)

xienkqul  于 2023-08-03  发布在  Oracle
关注(0)|答案(1)|浏览(306)

我试图使用www.example.com更改Oracle DB密码vb.net,它接受所有特殊字符,不包括分号(;)双引号(“”)。如果password包含分号,它将抛出未处理的异常,如“输入字符串格式不正确”。
database-version= Oracle Database 18c Enterprise Edition Release 18.0.0.0.0
我试过两种方法。一种是通过使用级联来构建连接串。另一种方法是使用连接字符串生成器。

Public Function oracle_connect(ByVal user As String, ByVal pwd As String, ByVal dbname As String) As 
Boolean
  Dim connection_String As String
  oracle_disconnect()
  oraclepwd = pwd
  oracleuser = user
  oraclehost = dbname
  connection_String = "User ID=" + oracleuser + ";Pooling=false;Data 
  Source=" + oraclehost +";Password=""" + oraclepwd + """;"       

  conn = New OracleConnection(connection_String)
  mycommand = conn.CreateCommand()

    Try
    ' ... (rest of the code)

    Catch ex As Exception
    ' Handle the exception

    End Try
End Function


 Public Function oracle_connect(ByVal user As String, ByVal pwd As String, ByVal dbname As String) As 
 Boolean
    Dim conn As OracleConnection = Nothing
    Dim oraclepwd As String = pwd
    Dim oracleuser As String = user
    Dim oraclehost As String = dbname

    Try
        Dim connStringBuilder As New OracleConnectionStringBuilder()
        connStringBuilder.UserID = oracleuser
        connStringBuilder.Password = oraclepwd
        connStringBuilder.DataSource = oraclehost
        connStringBuilder.Pooling = False

        conn = New OracleConnection(connStringBuilder.ConnectionString)
        conn.Open()
        Return True

    Catch ex As Exception
        ' Handle specific exceptions or display error messages
        Return False 
    Finally
        If conn IsNot Nothing AndAlso conn.State = ConnectionState.Open Then
            conn.Close()
        End If
    End Try
End Function

字符串

uyto3xhc

uyto3xhc1#

从SQL手册这里:
密码可以包含数据库字符集中的任何单字节、多字节或特殊字符,或这些字符的任意组合,但双引号(“)和返回字符除外。如果密码以非字母字符开头,或包含除字母数字字符、下划线(_)、美元符号($)或磅号(#)以外的字符,则必须用双引号引起来。否则,将密码括在双引号中是可选的。
我刚刚测试了一下:

SQL> create user tsc identified by "My;test123";

User created.

SQL> grant connect to tsc;

Grant succeeded.

SQL> connect tsc/"My;test123"@//localhost/test23
Connected.

字符串

相关问题