PHP Connection to MS SQL Server 2012

noa-dev

I have a problem which I can't seem to fix. My task is simple : I want to connect to the machine in our network which is an used IBM Server and has SQL running on it.

My PHP connection script is as following :

// Melde alle PHP Fehler
error_reporting(-1);
ini_set('display_errors', 1);
// Server in diesem Format: <computer>\<instance name> oder
// <server>,<port>, falls nicht der Standardport verwendet wird

error_reporting(E_ALL);
$serverName = "SERVERNAME\MSSQLSRV";

$connectionInfo = array('Database'=>'hgadb', "UID"=>"USERNAME", "PWD"=>"PASSWORD");
$conn = sqlsrv_connect($serverName, $connectionInfo);


if($conn) {
     "Connection established.<br />";
}else {
     "Connection could not be established.<br />";
    die(print_r(sqlsrv_errors(), true));
}

I am using the Microsoft SQL Server Management Tool and I have set up a Database with the name "hgadb" for test purpose as well as a Login for that database with the username hgadbuser and the matching password.

Everything seems to be set up, but I keep getting the same Error over and over again:

Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Fehler bei der Anmeldung f�r den Benutzer 'USERNAME'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Fehler bei der Anmeldung f�r den Benutzer 'USERNAME'. ) [1] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Die von der Anmeldung angeforderte hgadb-Datenbank kann nicht ge�ffnet werden. Fehler bei der Anmeldung. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Die von der Anmeldung angeforderte hgadb-Datenbank kann nicht ge�ffnet werden. Fehler bei der Anmeldung. ) [2] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Fehler bei der Anmeldung f�r den Benutzer 'USERNAME'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Fehler bei der Anmeldung f�r den Benutzer 'USERNAME'. ) [3] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Die von der Anmeldung angeforderte hgadb-Datenbank kann nicht ge�ffnet werden. Fehler bei der Anmeldung. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Die von der Anmeldung angeforderte hgadb-Datenbank kann nicht ge�ffnet werden. Fehler bei der Anmeldung. ) )

I know it's German - translated it says :

[message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]The from the login requested database:  DATABASENAME-Database cannot be opened. Error with login. ) )

What am I missing here?

update

When I am trying to login with SSMS over SQL Server Authentification I get the following error message

===================================

Cannot connect to SQL\MSSQLSRV.

===================================

Die Standarddatenbank des Benutzers kann nicht geöffnet werden. Fehler bei der Anmeldung.
Fehler bei der Anmeldung für den Benutzer 'USERNAME'. (.Net SqlClient Data Provider)

------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=4064&LinkId=20476

------------------------------
Server Name: SERVERNAME\MSSQLSRV
Error Number: 4064
Severity: 11
State: 1
Line Number: 65536


------------------------------
Program Location:

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at Microsoft.SqlServer.Management.SqlStudio.Explorer.ObjectExplorerService.ValidateConnection(UIConnectionInfo ci, IServerType server)
   at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()

When I login with windows authentification and change the database the user is trying to connect to to the "master" database in the folder system database (as seen on the picture below), then i am able to connect to that one with SSMS and my php connection doesn't show any errors.

Why can't I connect to one of my test databases?

enter image description here

noa-dev

Problem solved.

I had to set Permissions for the Database in SSMS for Guest and Public connections. Now it works properly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL Server 2012 Express connection to MS Access 2010

From Dev

Connection string for MS Access to Azure SQL Server 2012

From Dev

Connection string for MS Access to Azure SQL Server 2012

From Dev

PHP PDO load image into MS SQL Server 2012

From Dev

PHP PDO load image into MS SQL Server 2012

From Dev

Glassfish 3.1 JDBC Connection Pool to MS SQL Server 2012 named instance

From Dev

Error of connection to the MS SQL server

From Dev

SQL Query tuning - MS SQL Server -2012

From Dev

MS-SQl Server 2012 for ubuntu

From Dev

PHP connection with SQL server

From Dev

Is this connection string for SQL Server 2012 correct?

From Dev

How to create connection string for SQL Server 2012?

From Dev

HeidiSql connection to MS SQL Server LocalDB

From Dev

Connection Pool for Tomcat in Eclipse for MS Sql Server

From Dev

Connecting PHP to MS SQL Server

From Dev

Connecting PHP to MS SQL Server

From Dev

SQL Server JDBC connection exceptions for Windows authentication on Windows Server 2012

From Dev

SQL server connection using PHP

From Dev

SQL server connection using PHP

From Dev

How to use Dapper with MS SQL Server (2012) Geospatial / SQLGeography Column

From Dev

Hibernate with MS SQL Server 2012 issue with table locks and parallel query

From Dev

How to copy table from MS SQL Server 2012 to MonetDB

From Dev

How to debug unattended installation of MS SQL Server 2012?

From Dev

Sorting by similarity in alphanumeric string MS SQL Server 2012

From Dev

MS SQL Server 2012 Auto-Increment & Primary/Foreign Keys

From Dev

Connection to SQL Server Database inside Visual Studio 2012 C#

From Dev

VB .Net, SQL Server 2012 Express database connection

From Dev

Cannot connect to SQL Server 2012 (connection string issue?)

From Dev

Remote Connection to SQL Server 2012 Standard Edition port 1433

Related Related

  1. 1

    SQL Server 2012 Express connection to MS Access 2010

  2. 2

    Connection string for MS Access to Azure SQL Server 2012

  3. 3

    Connection string for MS Access to Azure SQL Server 2012

  4. 4

    PHP PDO load image into MS SQL Server 2012

  5. 5

    PHP PDO load image into MS SQL Server 2012

  6. 6

    Glassfish 3.1 JDBC Connection Pool to MS SQL Server 2012 named instance

  7. 7

    Error of connection to the MS SQL server

  8. 8

    SQL Query tuning - MS SQL Server -2012

  9. 9

    MS-SQl Server 2012 for ubuntu

  10. 10

    PHP connection with SQL server

  11. 11

    Is this connection string for SQL Server 2012 correct?

  12. 12

    How to create connection string for SQL Server 2012?

  13. 13

    HeidiSql connection to MS SQL Server LocalDB

  14. 14

    Connection Pool for Tomcat in Eclipse for MS Sql Server

  15. 15

    Connecting PHP to MS SQL Server

  16. 16

    Connecting PHP to MS SQL Server

  17. 17

    SQL Server JDBC connection exceptions for Windows authentication on Windows Server 2012

  18. 18

    SQL server connection using PHP

  19. 19

    SQL server connection using PHP

  20. 20

    How to use Dapper with MS SQL Server (2012) Geospatial / SQLGeography Column

  21. 21

    Hibernate with MS SQL Server 2012 issue with table locks and parallel query

  22. 22

    How to copy table from MS SQL Server 2012 to MonetDB

  23. 23

    How to debug unattended installation of MS SQL Server 2012?

  24. 24

    Sorting by similarity in alphanumeric string MS SQL Server 2012

  25. 25

    MS SQL Server 2012 Auto-Increment & Primary/Foreign Keys

  26. 26

    Connection to SQL Server Database inside Visual Studio 2012 C#

  27. 27

    VB .Net, SQL Server 2012 Express database connection

  28. 28

    Cannot connect to SQL Server 2012 (connection string issue?)

  29. 29

    Remote Connection to SQL Server 2012 Standard Edition port 1433

HotTag

Archive