Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to SSRS in PHP

I'm using SSRS SDK for PHP

PHP Version 5.4

webserver: Centos 6.4

MSSQL Server 2008 R2

define("UID", "*****\*****");
define("PASWD", "*****");
define("SERVICE_URL", "http://192.168.0.1/ReportServerURL/");
try {
  $ssrs_report = new SSRSReport(new Credentials(UID, PASWD), SERVICE_URL);
} catch (SSRSReportException $serviceException) {
  echo $serviceException->GetErrorMessage() . "<br>";
}

When I try to connect SSRS report, it is throughing the following error:

Failed to connect to Reporting Service Make sure that the url (http://192.168.0.1/ReportServerURL/) and credentials are correct!

The same credentials & link are accessible through browser without problem. But, through SSRS SDK it is not working.

I was looking for a solution in the net and I find that using the file TestSSRSConnection.php I could get more details but I dont know how to use it, and I cant find any documentation about it.

$testSSRSConnection = new TestSSRSConnection("/192.168.0.1/TESTREPORT/ReportServerURL/*****\*****/*****");
$testSSRSConnection->Parse();
$testSSRSConnection->TestConnection();

Testing it I get the following error:

Usage:TestSSRSConnection.php /server: /report: /uid: /pwd: [/datasource: /uid: /pwd:] 

Some idea how to go forward in this topic?

Update Doing a var_export($http_response_header))

I got

array (
      0 => 'HTTP/1.1 401 Unauthorized',
      1 => 'Content-Length: 0',
      2 => 'WWW-Authenticate: Negotiate',
      3 => 'WWW-Authenticate: NTLM',
      4 => 'Date: Tue, 04 Mar 2014 22:13:58 GMT',
      5 => 'Connection: close',
)
like image 242
Emilio Gort Avatar asked Dec 25 '22 12:12

Emilio Gort


1 Answers

The problem was with the Authentication Type.

By default, Reporting Services accepts requests that specify Negotiate and NTLM authentication. If your deployment includes client applications or browsers that use Basic authentication, you must add Basic authentication to the list of supported types.

To get the header response I added in the SSRSReport.php in the line 193

if ($content === FALSE) {
  throw new SSRSReportException("", "<br>Failed to connect to Reporting Service  <br/> Make sure   " .
  "that the url ($this->_BaseUrl) and credentials are correct!<br>" .
  var_export($http_response_header));//Line added by me to get the http header response
}

Output:

array (
   0 => 'HTTP/1.1 401 Unauthorized',
   1 => 'Content-Length: 0',
   2 => 'WWW-Authenticate: Negotiate',
   3 => 'WWW-Authenticate: NTLM',
   4 => 'Date: Tue, 04 Mar 2014 22:13:58 GMT',
   5 => 'Connection: close',
)

Failed to connect to Reporting Service
Make sure that the url (http://192.168.0.1/ReportServerURL/) and credentials are correct!

Adding Basic authentication to the SSRS solve the problem.

To configure a report server to use Basic authentication

1- Open RSReportServer.config in a text editor.

2- Find Authentication.

3- Copy one of the following XML structures that best fits your needs. The first XML structure provides placeholders for specifying all of the elements, which are described in the next section:

<Authentication>
    <AuthenticationTypes>
         <RSWindowsBasic>
               <LogonMethod>3</LogonMethod>
               <Realm></Realm>
               <DefaultDomain></DefaultDomain>
         </RSWindowsBasic>
    </AuthenticationTypes>
    <EnableAuthPersistence>true</EnableAuthPersistence>
</Authentication>

If you are using default values, you can copy the minimum element structure:

    <AuthenticationTypes>
         <RSWindowsBasic/>
    </AuthenticationTypes>

4- Paste it over the existing entries for .

If you are using multiple authentication types, add just the RSWindowsBasic element but do not delete the entries for RSWindowsNegotiate, RSWindowsNTLM, or RSWindowsKerberos.

To support the Safari browser, you cannot configure the report server to use multiple authentication types. You must specify only RSWindowsBasic and delete the other entries.

Note that you cannot use Custom with other authentication types.

5- Replace empty values for or with values that are valid for your environment.

6- Save the file.

7- If you configured a scale-out deployment, repeat these steps for other report servers in the deployment.

8- Restart the report server to clear any sessions that are currently open.

like image 97
Emilio Gort Avatar answered Jan 06 '23 21:01

Emilio Gort