VB.NET 中与 SQL Server 的无 DSN 连接
似乎在这里尝试了所有方法来使其正常工作,但是对于我可以在互联网领域找到的无 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然不是确切的答案,但这个网站一直对我有帮助:
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.
尝试创建 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