vb 创—SN 问题
strDriver = "MySQL ODBC 3.51 Driver" 'set the attributes delimited by null.
'See driver documentation for a complete
'list of supported attributes.
strAttributes = "SERVER=" & pstrServer & Chr(0)
strAttributes = strAttributes & "DESCRIPTION=" & pstrDescription & Chr(0)
strAttributes = strAttributes & "DSN=" & pstrDSN & Chr(0)
strAttributes = strAttributes & "DATABASE=" & pstrDataBase & Chr(0)
strAttributes = strAttributes & "UID=" & userid & Chr$(0)
strAttributes = strAttributes & "PWD=" & password & Chr$(0)
strAttributes = strAttributes & "Port=3306" & Chr$(0)
strAttributes = strAttributes & "Character set=gbk"
'Calls API to create DSN
CreateDSN = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver, strAttributes)
如上,除了红色部分其它都正常,请问Characterset这个参数是怎么写的?为什么我这样传不进去?
[解决办法]
要保证程序编码与浏览器编码一致,即程序编码与一致。
我改了连接串,设置了 character_set_results=uft8方式也不管用。真是个烦人的问题。
好在我冷静分析, 是不是因为driver版本问题。我的mysql driver版本为5.1的,而mysql为:4.0版本的。
重新去官方网站下载驱动,更改driver3.51版本的驱动,再去连接,果然成功!
connectionString="Driver={MySQL ODBC 3.51 Driver};Server=192.168.1.101;Port=3306;Option=131072;Stmt=;Database=mas; User=root;Password=123456"
[解决办法]
标准模块代码:
- VB code
Option ExplicitPublic Const ODBC_ADD_DSN = 1 '添加数据源Public Const ODBC_CONFIG_DSN = 2 '设置(编辑)数据源Public Const ODBC_REMOVE_DSN = 3 '移除数据源Public Const vbAPINull As Long = 0& '空指针Public Declare Function SQLConfigDataSource Lib "odbccp32.dll" ( _ ByVal hwndParent As Long, _ ByVal fRequestas As Integer, _ ByVal lpszDriver As String, _ ByVal lpszAttributes As String) As Long