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?