VB.NET 中与 SQL Server 的无 DSN 连接

发布于 2024-09-28 19:52:31 字数 1268 浏览 3 评论 0原文

似乎在这里尝试了所有方法来使其正常工作,但是对于我可以在互联网领域找到的无 dsn 连接字符串的几乎每次迭代,我不断收到“关键字不支持”错误,下面显示了两个错误。

Public cnSystem As New SqlClient.SqlConnection

Public Sub ConnectToSQL()

    Dim sConnectionString As String
    Dim sServer As String

    Try
        'Always connect to production server to get startup environment variables
        If gbIsProduction Then
            If gsProductionServer = "" Then
                sServer = "xxxxx-SQL"
            Else : sServer = gsProductionServer
            End If
        Else : sServer = gsDevelopmentServer
        End If
        //Doesn't work
        sConnectionString = "Network Library=DBMSSOCN;Data Source=xxxxx-SQL,1433;Inital Catalog=xxxxx;User ID=sa;Password=xxxxx;"
        //Doesn't work
        sConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;UserId=sa;Initial Catalog=xxxxx;Data Source=xxxxx-SQL;Password=xxxxx;"  
        cnSystem.ConnectionString = sConnectionString
        cnSystem.Open()
        cmdSystem.Connection = cnSystem
    Catch ex As Exception
        RaiseError("", "modGeneral." & System.Reflection.MethodBase.GetCurrentMethod().Name, Err.Number, Err.Description)
    End Try

End Sub

关于使用我正在使用的数据对象与 SQL 服务器进行无 DSN 连接的正确连接字符串有什么想法吗?

谢谢!

Tried seemingly everything here to get this to work but I keep getting "Keyword not supported" errors for just about every iteration of dsn-less connection strings I can find out there in internet land, two are shown below.

Public cnSystem As New SqlClient.SqlConnection

Public Sub ConnectToSQL()

    Dim sConnectionString As String
    Dim sServer As String

    Try
        'Always connect to production server to get startup environment variables
        If gbIsProduction Then
            If gsProductionServer = "" Then
                sServer = "xxxxx-SQL"
            Else : sServer = gsProductionServer
            End If
        Else : sServer = gsDevelopmentServer
        End If
        //Doesn't work
        sConnectionString = "Network Library=DBMSSOCN;Data Source=xxxxx-SQL,1433;Inital Catalog=xxxxx;User ID=sa;Password=xxxxx;"
        //Doesn't work
        sConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;UserId=sa;Initial Catalog=xxxxx;Data Source=xxxxx-SQL;Password=xxxxx;"  
        cnSystem.ConnectionString = sConnectionString
        cnSystem.Open()
        cmdSystem.Connection = cnSystem
    Catch ex As Exception
        RaiseError("", "modGeneral." & System.Reflection.MethodBase.GetCurrentMethod().Name, Err.Number, Err.Description)
    End Try

End Sub

Any ideas on what is the proper connection string for a DSN-less connection to a SQL server using the data objects I am using?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过度放纵 2024-10-05 19:52:31

虽然不是确切的答案,但这个网站一直对我有帮助:

http://www.connectionstrings.com/

另外,当使用 System.Data.SQLClient 时,您不必指定提供程序,我相信您会收到收到的错误。删除那部分。

While not the exact answer, this website helps me all the time:

http://www.connectionstrings.com/

Also, when using System.Data.SQLClient you do not have to specify the provider and I believe you will get the error you are receiving. Remove that part.

冰葑 2024-10-05 19:52:31

尝试创建 udl 文件来创建连接字符串。然后您可以测试它以确保它正常工作 - http://www.codeasp.net/blogs/hajan/microsoft-net/857/working-with-udl-universal-data-link-files

try creating a udl file to create your connection string. then you can test it to ensure it is working - http://www.codeasp.net/blogs/hajan/microsoft-net/857/working-with-udl-universal-data-link-files

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文