2014-03-02 31 views
1

我试图使用数据源属性来创建一个数据源,例如下面的例子:与数据源连接字符串属性到SQL Server

[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() 
{ 
} 

但我不断收到错误:

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.

为了能够连接到SQL服务器,创建连接字符串的正确格式是什么。另外,我在该机器上有ODBC连接,所以如果有办法使用ODBC的连接,我会更喜欢这种方式。

回答

1

假设你正在使用SQL Server的默认实例,DataSource.153.71.88.80,不能同时使用。此外,请将\\分开。

如果使用IP或主机名,可以肯定的是:

  • TCP/IP在SQL Server的配置中启用。
  • SQL Server的TCP端口1433(或者您可能设置的非默认端口)未被防火墙阻止。

如果目标SQL Server是本地的,那么我只需要使用. - 减少麻烦。

+1

我改变了连接字符串: [数据源( “System.Data.SqlClient的”, “数据源= 153.71.88.80;数据库= LoadData_For_R10Core_10_5_Final_Extended;集成安全性= TRUE;连接超时= 30;用户实例=真” ,“Products”,DataAccessMethod.Sequential)] 但是得到了完全相同的错误 –

+0

您确定TCP/IP已启用吗?你可以连接SSMS吗? – SqlACID

-1

那么,对我来说很难找到真正的方法来承担如何配置滴滴涕。 在这里,我找到了一个认为大约需要结构很好的解释: http://blogs.msdn.com/b/vstsqualitytools/archive/2006/01/10/511030.aspx

这里: http://msdn.microsoft.com/en-us/library/ms182527.aspx

我使用SQL Server和我不具有访问权限,因此,在全光照微软一般的例子,这是这个工作对我来说(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> 

变化{localhost}您的SQL服务器的名称或IP服务器(即192.18.130.26)。
我希望这可以帮助。

相关问题