设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1995|回复: 1
打印 上一主题 下一主题

如何使用代码在打开MDB数据库时登录SQL SERVER

[复制链接]
跳转到指定楼层
1#
发表于 2004-12-14 23:04:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在ACCESS中使用链接表进行对SQL Server的访问,但第一次访问数据库时,都会弹出一个登陆SQL Server的对话框,要求输入数据库帐号和密码,如果把这个用户名和密码交给用户自行输入,就会威胁到数据库的安全。如何在代码中实现这一功能。谢谢!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享分享 分享淘帖 订阅订阅
2#
发表于 2004-12-31 17:57:00 | 只看该作者
On Error GoTo err_hander    Dim strCn As String

    Dim strProvider As String

    Dim icn As New ADODB.Connection

    Dim intVersion As Integer

   

   

    intVersion = CurrentProject.Application.SysCmd(acSysCmdAccessVer)

   

'    strCN = "rovider=SQLOLEDB;Data Source=" & Me.txt_SQLServer & ";" _

'        & " Initial Catalog=ImportCS;User ID=" & Me.txt_SQLUID & "assword=" & Me.txt_SQLPWD & ";"

    strCn = "ersist Security Info=false;Data Source=" & Me.txt_SQLServer & ";User ID=" & Me.txt_SQLUID & ";Password=" & Me.txt_SQLPWD & ";Initial Catalog=ImportCS;Data Provider=SQLOLEDB.1"

   

    If intVersion < 9 Then

        MsgBox "&Igrave;á&Ecirc;&frac34;:±&frac34;&Iuml;&micro;&Euml;ù&ETH;&euml;&Ccedil;ó&micro;&Auml;×&icirc;&micro;&Iacute;ACCESS°&aelig;±&frac34;&Icirc;&ordf;Access 2000,&Ccedil;&euml;&Eacute;&yacute;&frac14;&para;&micro;&frac12;Access 2000&Ograve;&Ocirc;&Eacute;&Iuml;°&aelig;±&frac34;&ordm;ó&Ouml;&Oslash;&Ecirc;&Ocirc;!" & vbNewLine & "&Egrave;&ocirc;&Oacute;&ETH;&Icirc;&Ecirc;&Igrave;&acirc;&Ccedil;&euml;&Aacute;&ordf;&Iuml;&micro;&Iacute;&sup3;&sup1;&Uuml;&Agrave;í&Ocirc;±&raquo;ò&iquest;&ordf;·&cent;&Egrave;&Euml;&Ocirc;±&pound;&iexcl;&ETH;&raquo;&Ouml;&ordf;&pound;&iexcl;", vbOKOnly + vbInformation, "°&aelig;±&frac34;&Igrave;á&Ecirc;&frac34;!"

        GoTo exit_sub

    End If

    If intVersion > 9 Then '10 Version office xp 2003

        strProvider = "Provider=Microsoft.Access.OLEDB.10.0"

    Else

        strProvider = "Provider=MSDataShape.1"

    End If

   

   

    strCn = strProvider & ";" & strCn

    icn.Open strCn

   

    With CurrentProject

        With .Connection

            .Close

            .ConnectionString = strCn

            .Open

        End With

    End With    Me.Caption = "LONIN(" & Me.txt_SQLServer

   

    With Me.cboUID

        .RowSource = "select UID,NameEn,NameCn from tbl_def_user"

        .SetFocus

        .Dropdown

    End Withexit_sub:

    If Not icn Is Nothing Then

        If icn.State = adStateOpen Then icn.Close

        Set icn = Nothing

    End If

    Exit Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-22 20:52 , Processed in 0.099755 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表