57

For debugging purpose I'd like to know ways to test OLE DB connection string quickly.

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.

1
  • 2
    I just found this: "How to Test a Database Connection String using NotePad." Easy, quick and it worked beautifully. gotknowhow.com/articles/…
    – Jason H.
    Commented May 26, 2011 at 14:03

4 Answers 4

85

The following method has proven useful for me. It's super quick and practical and doesn't require 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.

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:

enter image description here

Go to your desktop and double-click on the TestConnection.udl file you just created and the Data Link Properties box will popup.

enter image description here

Select the Provider tab and Find the provider that you want to connect with and click Next >>.

enter image description here

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.

enter image description here

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.

enter image description here

Source

4
  • 11
    With this method you can not paste a connection string for testing.
    – Valentin
    Commented Dec 21, 2015 at 12:35
  • 3
    This is hands down, the best tip I have ever found on StackOverflow! If you create a connection @Valentin using the steps above, IIRC if you open the file in a text editor you will see the connection string which you can edit directly and subsequently open as a UDL file again.
    – Dead.Rabit
    Commented Apr 22, 2016 at 12:27
  • 4
    This does not address the original question. This is how to test SQL connectivity. The question is asking about testing connection strings.
    – Shadoninja
    Commented Feb 15, 2019 at 16:00
  • Perfectly worked for the machines to test connection to database. Commented May 20, 2019 at 10:56
76

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:

$conn = New-Object System.Data.OleDb.OleDbConnection
$conn.ConnectionString = "Provider=Search.CollatorDSO" # whatever you are testing
$conn.Open()
$conn.Close()
2
  • 1
    For me on Windows Server 2016 I get the error Exception calling "Open" with "0" argument(s): "No error message available, result code: DB_E_ERRORSOCCURRED(0x80040E21).", but @CJBS's answer below worked for me and doesn't require the Provider in the connection string stackoverflow.com/a/42842231/602585
    – deadlydog
    Commented Aug 3, 2018 at 4:40
  • @deadlydog Well CJBS's answer is not testing OLEDB, which is what this question is specifically about. It's testing the SQL Native provider (ADO.NET). They are completely different things. Commented Jul 3, 2022 at 4:50
47

SQL Server Native Connection string testing in PowerShell

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=xxxx at the start of this connection string.

First: Start → Run → 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 example this is based.

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.

1
  • "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." for sure!! Thanks for the info, as this is the #1 hit that I get.
    – xpt
    Commented Jan 5, 2022 at 21:18
16

There is one quick UI Method to Verify it

  1. Create an empty file: empty.txt
  2. rename the extension udl: empty.udl
  3. Now just double-click that file, it will ask the server and user name password, you gonna know how to do it.

enter image description here

Refer: http://www.gotknowhow.com/articles/test-a-database-connection-string-using-notepad

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.