如何動態創建ODBC連接(SQL SERVER)

dongfang2003 2006-09-27 11:19:14
--通用聲明
Private Const ODBC_ADD_DSN = 1 ' Add data source
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
Private Const vbAPINull As Long = 0&

Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) _
As Long
--聲明結束

--開始創建
Private Sub Command1_Click()
Dim intRet As Long
Dim strDriver As String
Dim strAttributes As String

'usamos el driver de SQL Server porque es el mas comun
strDriver = "SQL Server"
'Asignamos los parametros separados por null.
strAttributes = "SERVER=Server" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=db_mis" & Chr$(0)
strAttributes = strAttributes & "DSN=Db_mis" & Chr$(0)
strAttributes = strAttributes & "DATABASE=db_mis" & Chr$(0)
strAttributes = strAttributes & "UID=sa" & Chr$(0)
strAttributes = strAttributes & "PWD=" & Chr$(0)
intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver, strAttributes)
If intRet Then
MsgBox "DSN成功!"
Else
MsgBox "DSN失敗!"
End If
End Sub
--結束創建
問題:
如果去掉
strAttributes = strAttributes & "UID=sa" & Chr$(0)
strAttributes = strAttributes & "PWD=" & Chr$(0)
則創建成功,否則不成功
請問現在我一定要把login id 和密碼加進去,如何加才能成功呢

...全文
253 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
vbman2003 2007-04-04
  • 打赏
  • 举报
回复
http://support.microsoft.com/kb/184608/zh-cn
射天狼 2007-04-04
  • 打赏
  • 举报
回复
源码下载:
http://www.egooglet.com/static_html/200511121307434796admin.html

做鸡真好吃 2007-04-03
  • 打赏
  • 举报
回复
很失望~
jianxia88888 2006-10-05
  • 打赏
  • 举报
回复
strAttributes = strAttributes & "UID= '" & TextBox1.Text & "'" & Chr$(0)
strAttributes = strAttributes & "PWD= '" & TextBox2.Text & "'" & Chr$(0)
dongfang2003 2006-09-28
  • 打赏
  • 举报
回复
這個問題都沒人能解決,太令人失望了
dongfang2003 2006-09-27
  • 打赏
  • 举报
回复
加了密碼""也一樣不行,真是頭大了,誰能幫我解決這個問題呢
南山明月 2006-09-27
  • 打赏
  • 举报
回复
sql 里有密码,就算是"" 也是密码
所有要加

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧