I tried to backup my database following the instruction from SQL Server: Database stuck in "Restoring" state. but i have my database stuck in "Restoring" state. php code below:
$database = "container";
$uid = "sa";
$pwd = "12345" ;
try {
$conn = new PDO( "sqlsrv:Server=localhost\SQLEXPRESS;Database=$database",
$uid,
$pwd
//,array(PDO::ATTR_PERSISTENT => true)
);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); }
catch( PDOException $e ) {
die( "Error connecting to SQL Server" ); }
echo "Connected to SQL Server\n";
$backfile = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\sql server bk' ;
echo "Connected to SQL Server\n";
$backfile = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\sql server bk' ;
$query = "RESTORE DATABASE child_database FROM DISK = '$backfile' WITH REPLACE, RECOVERY ";
$conn->exec($query);
After running this code I got my child_database stuck in restoring state.however I copy the sql command
RESTORE DATABASE child_database FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\sql server bk' WITH REPLACE, RECOVERY
and run in microsoft sql server management tool it works just fine.
I try to run add php code
$conn->exec("RESTORE DATABASE child_database WITH RECOVERY");
I got an exception.
please help.
It seems have problem with PDO driver, this problem may be in the ODBC/SNAC layer on which the driver is built. But this database restoring works well with other drivers.
I tried with sqlsrv and mssql, they worked well.
For more detail, see Restoring a SQL Server Database from PHP
Related
How to get the SQL Server variables via the operating system?
Example:
ERROR LOG = D:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\Log\ERRORLOG
DB VERSION = 13.0.5026.0
DB HOME = D:\Program Files\Microsoft SQL Server\MSSQL13.SQL2012\MSSQL
INSTANCE NAME = SQL2012
I'm trying to capture the information by Powershell but with no success...
Attempts made:
Windows:
gci env:* | sort-object name
Regedit:
(get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server')
Please help.. I need to connect to a SQL Server database (B) from an Oracle database (A) which are both on Windows server machines. Here is what I did.
System DS created on (A):-
Name: ISECWM
Driver: ODBC Driver 11 for SQL Server
Test Results:
Microsoft ODBC Driver for SQL Server Version 12.00.5543
Running connectivity tests...
Attempting connection Connection established Verifying option settings
Disconnecting from server
TESTS COMPLETED SUCCESSFULLY!
$ORACLE_HOME/hs/admin/initISECWM.ora file contains
HS_FDS_CONNECT_INFO = ISECWM
HS_FDS_TRACE_LEVEL = OFF
$ORACLE_HOME/network/admin/listener.ora updated:-
SID_LIST_LISTENER = (SID_LIST = (SID_DESC =
(SID_NAME=ISECWM)
(ORACLE_HOME=c:\oracle\11g)
(PROGRAM=dg4odbc)
) )
$ORACLE_HOME/network/admin/tnsnames.ora updated:-
WORLDMAP.DBL = (DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=SERVER A HOSTNAME)(PORT=1521))
(CONNECT_DATA=(SID=ISECWM)) (HS=OK) )
Database link created:-
CREATE PUBLIC DATABASE LINK TSTDBLINK CONNECT TO "sql server
username" IDENTIFIED BY "sql server password" USING 'WORLDMAP.DBL';
Tested the database link with:-
select * from dual#TSTDBLINK; --gives the error
Error:-
ORA-28513: internal error in heterogeneous remote agent ORA-02063:
preceding line from TSTDBLINK
28513. 00000 - "internal error in heterogeneous remote agent"
*Cause: An internal error has occurred in the Oracle remote agent
supporting a heterogeneous database link.
*Action: Make a note of how the error was produced and contact the
customer support representative of the agent vendor. Error at Line: 7 Column: 20
Ah, finally Oracle helped me with the issue.
It seems I had 2 homes, I put the initISECWM.ora in the wrong Oracle home.
Just copied and pasted it in the other home/hs/admin/ and it worked like a wonder! Voila!
I am using Powershell to a script to dynamically restore a database (sql server 2012).
set-location "SQLSERVER:\sql\$host_name\$inst\databases\.$db_target"
$db = Invoke-Sqlcmd -Query "select type_desc,name,physical_name from sys.master_files where database_id=db_id(N'$db_target') order by type_desc desc "
When I execute the script I get the following error message :
DBMS MSG - ODBC return code <-1>, SQL State <37000>, SQL Message
<3101><[Microsoft][SQL Server Native Client 10.0][SQL Server]Exclusive
access could not be obtained because the database is in use.>.
I then use SSMS to make the database offline
alter database [db_target] set offline with rollback immediate
After this my script works fine.
Question :
Why is invoke_sqlcmd not closing the session?
Can I execute the alter database .... command from my powershell script?
Thanks
I created the database on SQL Server 2008 and connect to it
{.ConnectionString = "Server=.\SQLEXPRESS;Database=Test;User=sa;Pwd=test;"}
Now i want to deploy that application so my friend can test it. I have no idea how to make it possible or is it possible at all ( is the database on my localhost ) ?
I would really could use some help because first time working with it.
You can create local mdf database file in your project and slightly change your connection string to attach it to sqlexpress instance.
"Data Source=.\SQLEXPRESS;
AttachDbFilename=test.mdf;
Integrated Security=True;
User Instance=True";
It worth to mension that your friend has to have sql server express installed.
I think the best way is to make a backup of your DB as follows.BACKUP DATABASE [Accounting] TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\Test.bak' WITH NOFORMAT, INIT, NAME = N'Accounting-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
then they can restore it as follows on there mssqlserver:
RESTORE DATABASE [DBRooiabooking] FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\Test.bak' WITH FILE = 1, NOUNLOAD, STATS = 5
and they can use it .
with the same connectionstring .
Best Regards
I'm talking to an SQL server 2005 using PHP's PDO API:
$mssql = new PDO('dblib:host=foohost;dbname=foodb', 'foouser', 'foopassword');
Subsequently, I want to backup the database to a local file as shown in the code below - which then fails.
$query = "
BACKUP DATABASE foodb
TO DISK = 'D:\\migration\\test_backup.bak';
GO
";
$stmt = $mssql->prepare($query);
$stmt->execute();
The error I'm getting is this (result from $stmt->errorInfo()):
[0] => HY000
[1] => 102
[2] => General SQL Server error: Check messages from the SQL Server [102] (severity 15) [(null)]
[3] => -1
[4] => 15
I've tried to do the same thing using SQL Server Management Studio, and the exact same query works. So - any hints on how I could get this to work (Note: I'm forced to use PHP on a remote linux host, so any local windows tools won't work)