Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12554

SQLSERVER 2012

$
0
0

Hi

I am trying to setup PHP 5.4.13 ( VC9 x86 Thread Safe (2013-Mar-15 04:08:07)) to work with Apache 2.4 running as localhost on port 80 and SQLServer 2012 (Express) using the 3.0.1  Windows PHP drivers (SQLSRV30.EXE from http://www.microsoft.com/en-au/download/details.aspx?id=20098) on  Windows 8 on a 64 bit Intel P4 system. (Gave up trying to get the 64 bit versions going with PHP drivers 32 bit) and installed 32 bit versions of PHP and Apache as above both of which are working fine. When I try to connect from an ExampleForm to an ExampleDB which was created on the default SQLEXPRESS instance (DAVID-PC\SQLEXPRESS on my machine) using MS SQL Management Studio) using Windows Authentication

with the following code

<html>
<head>
<Title>Example Web Form</Title>
</head>
<body>
<form method="post" action="?action=add" enctype="multipart/form-data" >
    Last name <input type="text" name="lastName" id="lastName"/></br>
    First name <input type="text" name="firstName" id="firstName"/></br>
    E-mail address <input type="text" name="emailAddress" id="emailAddress"/></br>
        <input type="submit" name="submit" value="Submit" />
</form>
<?php
$serverName = "DAVID-PC\SQLEXPRESS";
/* connect using Windows Authentication */
$connectionOptions = array("Database"=>"DAVID-PC\SQLEXPRESS\ExampleDB");
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn === false)
{
    echo "Unable to connect <br />";
    die(print_r(sqlsrv_errors(), true));
}
else
{
echo "Connected to DAVID-PC\SQLEXPRESS\ExampleDB";
}sqlsrv_close( $conn);
?>
</body>
</html>

I get the error

Login failed for 'NT AUTHORITY\SYSTEM' Cannot open the database 'DAVID-PC\SQLEXPRESS\ExampleDB' requested by login. The login failed.

Checking in MSS Management Studio

NT AUTHORITY\SYSTEM exists under Security\Logins both for DAVID-PC\SQLEXPRESS and the ExampleDB which is attached to the instance of the server  E.g. executing

USE [master]
GO
CREATE LOGIN [NT AUTHORITY\SYSTEM] FROM WINDOWS WITH DEFAULT_DATABASE=[master]
GO
USE [ExampleDB]
GO
CREATE USER [NT AUTHORITY\SYSTEM] FOR LOGIN [NT AUTHORITY\SYSTEM]
GO
ALTER USER [NT AUTHORITY\SYSTEM] WITH DEFAULT_SCHEMA=[DBO]
GO
EXEC sp_addrolemember N'db_owner', N'NT AUTHORITY\SYSTEM'
GO

produces

Msg 15025, Level 16, State 2, Line 1
The server principal 'NT AUTHORITY\SYSTEM' already exists.

in MSSMS

and executing the following Query in MSSMS

SELECT * FROM sys.server_principals WHERE name LIKE 'NT AUTHORITY\SYSTEM'

 produces

NT AUTHORITY\SYSTEM    269    0x010100000000000512000000    U    WINDOWS_LOGIN    0    2013-03-18 20:08:59.863    2013-03-18 20:08:59.870   master    us_english    NULL    NULL    0

don't understand why this wont work?. Am I missing something obvious

Viewing all articles
Browse latest Browse all 12554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>