I'm trying to insert the data from a text file into my database. I'm using SQL Server Management Studio 17.
I'm using this query:
BULK INSERT db.[dbo].[mytable]
FROM 'path/file.txt'
WITH
(FIELDTERMINATOR = ';',
ROWTERMINATOR = '\n')
The problem is that it's working in SQL Server Management Studio but when i'm trying to execute this php script it shows an error even though I granted the user the permission to bulk after following this:
You do not have permission to use the bulk load statement
The error:
Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 4834 [code] => 4834 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]You do not have permission to use the bulk load statement. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]You do not have permission to use the bulk load statement. ) )
The code i'm using
<?php
$serverName = "SQLEXPRESS";
$connectionInfo = array( "Database"=>"master");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$query1 = "BULK INSERT db.[dbo].[mytable]
FROM 'path/file.txt'
WITH
(FIELDTERMINATOR = ';',
ROWTERMINATOR = '\n')";
$result1 = sqlsrv_query($conn,$query1) or die( print_r(sqlsrv_errors(), true) );
?>
ALTER SERVER ROLE bulkadmin ADD MEMBER {Your PHP SQL Login};(obviously replace the text in the braces ({})).