2

I'm trying to create a DataSource using the DataSource attribute, like in the next example:

[TestMethod]
[DataSource("System.Data.SqlClient", "Data Source=.\\153.71.88.80;Database=LoadData_For_R10Core_10_5_Final_Extended;Integrated Security=True;Connect Timeout=30;User Instance=True", "Products", DataAccessMethod.Sequential)]
public void GetProducts()
{
}

But I keep getting the error:

The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library.

What is the correct format to create the connection string in order to be able to connect to the SQL server. Also, I have ODBC connection on that machine, so if there is a way to use the connection of ODBC I will prefer that.

0

2 Answers 2

1

Assuming you are using a default instance of SQL Server, DataSource should be . or 153.71.88.80, not both. Also, drop the \\ separating them.

If you use an IP or hostname, be sure that:

  • TCP/IP is enabled in the SQL Server's configuration.
  • TCP port 1433 (or a non-default port you may've set) for SQL Server is not firewall-blocked.

If the target SQL Server is local, I would just use . - less trouble.

2
  • 1
    I changed the connection string to: [DataSource("System.Data.SqlClient", "Data Source=153.71.88.80;Database=LoadData_For_R10Core_10_5_Final_Extended;Integrated Security=True;Connect Timeout=30;User Instance=True", "Products", DataAccessMethod.Sequential)] But got exactly the same error Mar 2, 2014 at 16:49
  • Did you make sure TCP/IP is enabled? Can you connect with SSMS?
    – SqlACID
    Mar 2, 2014 at 17:19
-1

Well, for me was hard to find the real way to undertood how to configure DDT. Here, I found what a think is a great explanation about the structure needed: http://blogs.msdn.com/b/vstsqualitytools/archive/2006/01/10/511030.aspx

and here: http://msdn.microsoft.com/en-us/library/ms182527.aspx

I am using SQL Server, and I don´t have Access, so, usin the general example from Microsoft, this is the way this worked for me (VB.Net):

< TestMethod() > 
< DataSource("System.Data.SqlClient", "Data Source=localhost;Initial Catalog=Prueba;Integrated Security=True", "AccountTest", DataAccessMethod.Sequential) >

Public Sub AddIntegerHelper_DataDrivenValues_AllShouldPass()   <br>
    Dim target As New CheckingAccount()   <br>
    Dim x As Integer = Convert.ToInt32(tscntx.DataRow("FirstNumber"))   <br>
    Dim y As Integer = Convert.ToInt32(tscntx.DataRow("SecondNumber"))  <br>
    Dim expected As Integer = Convert.ToInt32(tscntx.DataRow("Sum"))  <br>
    Dim actual As Integer = target.AddIntegerHelper(x, y)  <br>
    Assert.AreEqual(expected, actual)  <br>
End Sub  <br>

Change {localhost} for your sql server name or the IP server (i.e. 192.18.130.26).
I hope this helps.

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.