.net 测试 OLE DB 连接字符串的快速方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3910364/
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
Quick ways to test OLE DB Connection String
提问by Michael Mao
For debugging purpose I'd like to know ways to test OLE DB connection string quickly.
出于调试目的,我想知道快速测试 OLE DB 连接字符串的方法。
I've found this free software, it works on my machine, tested successfully.
我找到了这个免费软件,它在我的机器上运行,测试成功。
Is there a even quicker way to do so, maybe from command line on Windows? Because most of the time, it is the client rather than me that would do this task, so I prefer a "zero-installation" approach that would impact their system the least.
有没有更快的方法,也许从 Windows 上的命令行?因为大多数时候,是客户而不是我来完成这项任务,所以我更喜欢“零安装”的方法,这种方法对他们的系统影响最小。
回答by Daniel
The following method has proven useful for me. It's super quick and practical and doesn't require PowerShell:
事实证明,以下方法对我很有用。它超级快速且实用,并且不需要 PowerShell:
- Open up Notepad and create an empty text file, then click File -> click Save -> and save it with the File name: TestConnection.udl to your desktop.
- Go to your desktop and double-click on the TestConnection.udl file you just created and the Data Link Properties box will popup.
- Select the Provider tab and Find the provider that you want to connect with and click Next >>.
- Now from the Connection tab, select or enter your source/ server name -> then enter information to log on to server -> and select the database on the server.
- Click Test Connection and click OK to save the file. If errors occur during testing of your connection string, you will get a popup box with the error message.
- 打开记事本并创建一个空文本文件,然后单击文件 -> 单击保存 -> 并使用文件名将其保存到桌面:TestConnection.udl。
- 转到您的桌面并双击您刚刚创建的 TestConnection.udl 文件,将弹出数据链接属性框。
- 选择提供者选项卡并找到您要连接的提供者,然后单击下一步 >>。
- 现在从连接选项卡中,选择或输入您的源/服务器名称 -> 然后输入信息以登录服务器 -> 并选择服务器上的数据库。
- 单击“测试连接”,然后单击“确定”以保存文件。如果在测试连接字符串期间发生错误,您将看到一个包含错误消息的弹出框。
Walkthrough(same as above but with images)
演练(同上,但有图片)
Open up Notepad and create an empty text file, then click File -> click Save -and save it with the File name: TestConnection.udl to your desktop:
打开记事本并创建一个空文本文件,然后单击文件 -> 单击保存 - 并使用文件名将其保存:TestConnection.udl 到您的桌面:
Go to your desktop and double-click on the TestConnection.udl file you just created and the Data Link Properties box will popup.
转到您的桌面并双击您刚刚创建的 TestConnection.udl 文件,将弹出数据链接属性框。
Select the Provider tab and Find the provider that you want to connect with and click Next >>.
选择提供者选项卡并找到您要连接的提供者,然后单击下一步 >>。
Now from the Connection tab, select or enter your source/ server name -> then enter information to log on to server -> and select the database on the server.
现在从连接选项卡中,选择或输入您的源/服务器名称 -> 然后输入信息以登录服务器 -> 并选择服务器上的数据库。
Click Test Connection and click OK to save the file. If errors occur during testing of your connection string, you will get a popup box with the error message.
单击“测试连接”,然后单击“确定”以保存文件。如果在测试连接字符串期间发生错误,您将看到一个包含错误消息的弹出框。
回答by Chuck Heatherly
If the client has PowerShell installed (a given if they are running Windows 7 or Windows Server 2008 R2), then you can execute these commands from a PowerShell console window:
如果客户端安装了 PowerShell(如果它们运行的是 Windows 7 或 Windows Server 2008 R2),那么您可以从 PowerShell 控制台窗口执行这些命令:
$conn = New-Object System.Data.OleDb.OleDbConnection
$conn.ConnectionString = "Provider=Search.CollatorDSO" # whatever you are testing
$conn.Open()
$conn.Close()
回答by CJBS
SQL Server Native Connection string testing in PowerShell
PowerShell 中的 SQL Server 本机连接字符串测试
This method works in Powershell for testing an SQL Server Native connection string (the type that might work with a SQL Server database and be used in a web.config file). Note that there's no Provider=xxxxat the start of this connection string.
此方法适用于 Powershell,用于测试 SQL Server Native 连接字符串(可能与 SQL Server 数据库一起使用并在 web.config 文件中使用的类型)。请注意,Provider=xxxx此连接字符串的开头没有。
First: Start → Run → PowerShell
首先:开始→运行→PowerShell
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Data Source=(local)\SQLExpress;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=MyDBUser;Password=IShouldBeUsingIntegratedSecurity!;MultipleActiveResultSets=True;User Instance=False"
# If no error occurs here, then connection was successful.
$conn.Open();
$conn.Close();
SqlConnection Class documentation.
Kudos to @Chuck Heatherly, on whose examplethis is based.
感谢@Chuck Heatherly,这是基于他的例子。
Note: I'm fully aware that this question is for OLEDB, however having come here looking for a means of doing this for a SQL Native connection, this might be of use to others who arrive here with the same goal.
注意:我完全知道这个问题是针对 OLEDB 的,但是来到这里是为了寻找一种针对 SQL Native 连接执行此操作的方法,这可能对以相同目标到达这里的其他人有用。
回答by Xin
There is one quick UI Method to Verify it
有一种快速的 UI 方法来验证它
- Create an empty file:
empty.txt - rename the extension udl:
empty.udl - Now just double-click that file, it will ask the server and user name password, you gonna know how to do it.
- 创建一个空文件:
empty.txt - 重命名扩展 udl:
empty.udl - 现在只需双击该文件,它会询问服务器和用户名密码,你会知道怎么做的。
Refer: http://www.gotknowhow.com/articles/test-a-database-connection-string-using-notepad
参考:http: //www.gotknowhow.com/articles/test-a-database-connection-string-using-notepad


