1676673 - Error: 'Failed to open the connection. Details: [Database Vendor Code: 17]' running a report in a .NET web application

SAP Knowledge Base Article - Public

1676673 - Error: 'Failed to open the connection. Details: [Database Vendor Code: 17]' running a report in a .NET web application

Symptom

  • While opening the report in custom .NET web application error is thrown.
  • Error: Failed to open the connection. Details: [Database Vendor Code: 17]

dbvendor17.jpg

Environment

  • Windows 7
  • Visual Studio 2010
  • Crystal Reports for Visual Studio 2010
  • SQL Server 2008 R2
  • Web application using .NET Framework 4.0

Cause

  • Error code 17 refers to SQL Server does not exist or access denied.
  • Code was missing the setting for tables connectivity due to which it was not able to connect to the database.

Resolution

  • Set the TableLogOnInfo object for a tables using following code:

In VB.NET

Private Sub ConfigureCrystalReports()
        Dim reportPath As String = Server.MapPath("NorthwindCustomers.rpt")
        myCrystalReportViewer.ReportSource = reportPath
        Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
        SetDBLogonForReport(myConnectionInfo)
        myConnectionInfo.ServerName = "localhost"
        myConnectionInfo.DatabaseName = "Northwind"
        myConnectionInfo.UserID = "limitedPermissionAccount"
        myConnectionInfo.Password = "1234"
    End Sub
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        ConfigureCrystalReports()
    End Sub
    Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo)
        Dim myTableLogOnInfos As TableLogOnInfos = myCrystalReportViewer.LogOnInfo
        For Each myTableLogOnInfo As TableLogOnInfo In myTableLogOnInfos
            myTableLogOnInfo.ConnectionInfo = myConnectionInfo
        Next
    End Sub
 

In C#

 private void ConfigureCrystalReports()
    {
        string reportPath = Server.MapPath("NorthwindCustomers.rpt");
        
        ConnectionInfo connectionInfo = new ConnectionInfo();
        
        connectionInfo.ServerName = "localhost";
        connectionInfo.DatabaseName = "Northwind";
        connectionInfo.UserID = "limitedPermissionAccount";
        connectionInfo.Password = "1234";
        crystalReportViewer.ReportSource = reportPath;
        SetDBLogonForReport(connectionInfo);
    }
    private void Page_Init(object sender, EventArgs e)
    {
        ConfigureCrystalReports();
    }
    private void SetDBLogonForReport(ConnectionInfo connectionInfo)
    {
        TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo;
        foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
        {
            tableLogOnInfo.ConnectionInfo = connectionInfo;
        }
    } 

Keywords

KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio