请教VB+SQL2000问题,在线等

ajianchen2002 2004-09-22 10:17:25
我用我自己的机器做服务器又做客户端,在本机上测试可以正常连接
如果到局域网的其他机器上怎么连接呢?
用IP可以连接吗?还有就是需要做什么设置?我杂本机测试时,不知道为什么不需要用户名和密码就可正常连接(我第一次用SQL当初建数据库时,我是用ACCESS数据库直接导入到SQL2000 的),现在问题是要是在其他机器上连接我的数据库,我的机器作为服务器来用,需要怎么连接,怎么设置?
请各位大哥大姐赐教
非常感谢
...全文
106 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ajianchen2002 2004-09-22
  • 打赏
  • 举报
回复
楼上的大哥,小弟不太懂你的程序,函数返回的结果是什么呢?
不过先试试在说吧
ch_gufen 2004-09-22
  • 打赏
  • 举报
回复
我靠,这样的问题问我饿.哈哈,
用dsn.手工设置以下odbc.或者用代码建立dsn.或者采用非dsn连接.
代码建dsn
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& ' NULL Pointer
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

Sub CreatDSN()

Dim intRet As Long
Dim strDriver As String
Dim strAttributes As String
strDriver = "Microsoft Access Driver (*.mdb)"----------这里要修改成sqlserver
'null 结尾的参数
'请看相关文档
'strAttributes = "SERVER=SomeServer" & Chr$(0)
'strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)'这里要修改

strAttributes = strAttributes & "DSN=tsgl" & Chr$(0)'这里要修改

strAttributes = strAttributes & "DBQ=" & App.Path & "\dbase.mdb" & Chr$(0)'这里要修改
'strAttributes = strAttributes & "UID=admin" & Chr$(0) ''这里要修改

'strAttributes = strAttributes & "PWD=" & Chr$(0)'这里要修改

'如果要显示对话,可使用 Form1.Hwnd 代替 vbAPINull.
intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver, strAttributes)
End Sub

以上是在我的软件里copy的.access的dsn代码建立用sqlserver 要改以下eeeeeee
wonsin 2004-09-22
  • 打赏
  • 举报
回复
呵呵,些问题我也曾经碰到过,我开始也是用 tztz520(午夜逛街) 那种方法来连的,客户端不认,后用DSN来连的,在WIN2003和XP上都没问题,WIN2000就不行,再后来在客户端安装了SQL2000的客户后,稍加设置DSN就OK了!
tztz520 2004-09-22
  • 打赏
  • 举报
回复

"Provider=sqloledb;Data Source=192.168.1.11;Initial Catalog=" & "csdb" & ";User Id=sa;Password=1234"
zichen66 2004-09-22
  • 打赏
  • 举报
回复
不需要用戶名和密碼可能是你在SQLSERVER的登錄中使用了<Windows帳戶登錄>而不是用的<使用SqlServer的帳戶登錄>,
你使用IP來聯接當然是可以的,也可以用電腦名<當此電腦上只安裝了一個實例的時候>
chinaIT 2004-09-22
  • 打赏
  • 举报
回复
Public Function ConnectString() As String
ConnectString = "driver={SQL Server};server=" & 服务器名称 & ";uid=用户名;pwd=密码;database=数据库"
End Function

Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
'executes SQL and returns Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String


' On Error GoTo ExecuteSQL_Error
sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
If InStr("INSERT,DELETE,UPDATE", _
UCase$(sTokens(0))) Then
cnn.Execute SQL
MsgString = sTokens(0) & _
" query successful"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, _
adOpenKeyset, _
adLockOptimistic

'rst.MoveLast 'get RecordCount


Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & " 条记录 "
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function

ExecuteSQL_Error:
MsgString = "查询错误: " & Err.Description
Resume ExecuteSQL_Exit
End Function
以上放在模块中;
在程序中:

Dim txtSQL As String
Dim MsgText As String
Dim ADOname As ADODB.Recordset

txtSQL = "select * from 表"
Set ADOname = ExecuteSQL(txtSQL, MsgText)

1,216

社区成员

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

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