硬编码连接字符串有效,内置连接字符串无效';t(VB6到SQL Server 2008 R2)

硬编码连接字符串有效,内置连接字符串无效';t(VB6到SQL Server 2008 R2),vb6,connection-string,sql-server-express,sql-server-2008-r2,Vb6,Connection String,Sql Server Express,Sql Server 2008 R2,构建VB6程序可用于连接SQL Server 2008 R2数据库的连接字符串时遇到问题。当我在我的程序中硬编码连接字符串时,它工作正常,并且我能够访问数据库。以下是有效的代码: gcnTheEstimator.Open "Provider=SQLNCLI10;Server=KEVIN-PC;Database=The_Estimator", "sa", "" 但是,以下两项工作均不适用: gcnTheEstimator.ConnectionString = "Provider=SQLNCLI1

构建VB6程序可用于连接SQL Server 2008 R2数据库的连接字符串时遇到问题。当我在我的程序中硬编码连接字符串时,它工作正常,并且我能够访问数据库。以下是有效的代码:

gcnTheEstimator.Open "Provider=SQLNCLI10;Server=KEVIN-PC;Database=The_Estimator", "sa", ""
但是,以下两项工作均不适用:

gcnTheEstimator.ConnectionString = "Provider=SQLNCLI10;Server=KEVIN-PC;Database=The_Estimator, sa"

gcnTheEstimator.Open
(运行它会显示以下错误消息:授权规范无效)

(使用msgbox显示此连接字符串返回的连接字符串与上面显示的可用硬编码字符串完全相同。但是,运行它会显示以下错误消息:[Microsoft][ODBC驱动程序管理器]未找到数据源名称,并且未指定默认驱动程序。)

我试过其他几种变体,但都不管用


我需要在另外两个都使用SQL Server 2008 R2的位置部署VB6程序,因此我需要在我的程序中构建它们的连接字符串。我做错了什么?TIA

gcnTheEstimator.Open
需要3个参数,每个参数用逗号分隔(您试图在单个字符串变量中提供所有三个参数)。这应该起作用:

dim connStr as string
dim usernameStr as string
dim passwordStr as string

connStr = "Provider=SQLNCLI10;Server=KEVIN-PC;Database=The_Estimator"
usernameStr = "sa"
passwordStr = ""

gcnTheEstimator.Open connStr, usernameStr, passwordStr

成功了!我可以发誓我也试过,但我想我一定没试过。谢谢
dim connStr as string
dim usernameStr as string
dim passwordStr as string

connStr = "Provider=SQLNCLI10;Server=KEVIN-PC;Database=The_Estimator"
usernameStr = "sa"
passwordStr = ""

gcnTheEstimator.Open connStr, usernameStr, passwordStr