vb6 ADODB 连接字符串到 sql server 2008

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2962296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 06:26:26  来源:igfitidea点击:

vb6 ADODB connection string to sql server 2008

sqlsql-server-2008connection-string

提问by phill

I recently migrated a database from sql server 2005 to 2008 on windows server 2008. Clients connect fine from their XP machines and so does the SQL Management Studio 2008. I have also tested a remote connection using LINQPad which worked fine.

我最近在 windows server 2008 上将数据库从 sql server 2005 迁移到 2008。客户端从他们的 XP 机器连接正常,SQL Management Studio 2008 也是如此。我还测试了使用 LINQPad 的远程连接,它工作正常。

However on my VB6 app, the connection string seems to give me problems. Any ideas what I'm doing wrong?

但是在我的 VB6 应用程序上,连接字符串似乎给我带来了问题。任何想法我做错了什么?

    Dim strUserName As String
     Dim strPassword As String
     Dim sProc As String

     sProc = "Class_clsAdoFnx_Initialize"

        Me.DatabaseName = "db_app"




 'Connect to SQL Server

    strUserName = "admin"
    strPassword = "mudslinger"

    Set cSQLConn = New ADODB.Connection
    '**Original connection String
    'cSQLConn.CommandTimeout = 0
    'cSQLConn.ConnectionString = " PROVIDER=SQLOLEDB" & _
    '    ";SERVER=NET-BRAIN" & _
    '    ";UID=" & strUserName & _
    '    ";PWD=" & strPassword & _
    '    ";DATABASE=" & Me.DatabaseName

    '***First attempt, no dice
    'cSQLConn.ConnectionString = "Provider=sqloledb;" & _
    '       "Data Source=NET-BRAIN;" & _
    '       "Initial Catalog=DB_APP;" & _
    '       "User Id=admin;" & _
    '       "Password=mudslinger"
    'cSQLConn.Open

    '***3rd attempt, no dice 
    cSQLConn.Open "Provider=sqloledb;" & _
           "Data Source=NET-BRAIN;" & _
           "Initial Catalog=db_app;" & _
           "User Id=admin;" & _
           "Password=mudslinger", "admin", "mudslinger"

thanks in advance.

提前致谢。

UPDATE: Here is the string I generated using my test.UL file

更新:这是我使用 test.UL 文件生成的字符串

[ODBC] Provider

[ODBC] 提供程序

Provider=MSDASQL.1;Password=logmein;Persist Security Info=True;User ID=sa;Extended Properties="DSN=NET-BRAIN;UID=admin;PWD=mudslinger;APP=Microsoft? Windows? Operating System;WSID=BPOOR-16D68FBC7D;DATABASE=DB_App;Network=DBMSSOCN";Initial Catalog=DB_App

Provider=MSDASQL.1;Password=logmein;Persist Security Info=True;User ID=sa;Extended Properties="DSN=NET-BRAIN;UID=admin;PWD=mudslinger;APP=Microsoft?Windows?操作系统;WSID= BPOOR-16D68FBC7D;DATABASE=DB_App;Network=DBMSSOCN”;初始目录=DB_App

Here is the same UL file using the SQL Native provider:

这是使用SQL Native 提供程序的相同 UL 文件:

"Provider=SQLNCLI10.1;Integrated Security="";Persist Security Info=False;User ID=admin;Initial Catalog=DB_APP;Data Source=NET-BRAIN;Initial File Name="";Server SPN="""

"Provider=SQLNCLI10.1;Integrated Security="";Persist Security Info=False;User ID=admin;Initial Catalog=DB_APP;Data Source=NET-BRAIN;Initial File Name="";Server SPN="""

--received the error: Error in Ado Call... There was an error in Class_clasAdoFnx_initialize 3001 Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. --Error: Class_clsAdoFnx_Initialize 3709 Requested operation requires an OLE DB Session object, which is not supported by current provider.

--received the error: Error in Ado Call... Class_clasAdoFnx_initialize 3001 中出现错误 参数类型错误、超出可接受范围或相互冲突。--错误:Class_clsAdoFnx_Initialize 3709 请求的操作需要 OLE DB 会话对象,当前提供程序不支持该对象。

tried [oledb] for sql server provider option"Provider=SQLOLEDB.1;Password=mudslinger;Persist Security Info=True;User ID=admin;Initial Catalog=db_app;Data Source=net-brain"

尝试 [oledb] for sql server provider 选项“Provider=SQLOLEDB.1;Password=mudslinger;Persist Security Info=True;User ID=admin;Initial Catalog=db_app;Data Source=net-brain”

error: -2147217900 Login failed for user 'admin'

错误:-2147217900 用户“admin”登录失败

UPDATE2 :After isolating the open connection string, it turns out the connection is opening and the stored procedure I was using to test with was failing.

UPDATE2 :在隔离打开的连接字符串后,结果证明连接正在打开并且我用来测试的存储过程失败了。

采纳答案by volody

Following Using ADO with SQL Server Native Clientto enable the usage of SQL Server Native Client, ADO applications will need to implement the following keywords in their connection strings:

将 ADO 与 SQL Server Native Client一起使用以启用 SQL Server Native Client 之后,ADO 应用程序将需要在其连接字符串中实现以下关键字:

Provider=SQLNCLI10
DataTypeCompatibility=80

提供程序=SQLNCLI10 数据
类型兼容性=80

Dim con As New ADODB.Connection

con.ConnectionString = "Provider=SQLNCLI10;" _
         & "SERVER=NET-BRAIN;" _
         & "Database=DB_APP;" _ 
         & "DataTypeCompatibility=80;" _
         & "User Id=admin;" _
         & "Password=mudslinger;"

con.Open