Category Archives: MSSQL

MSSQL DB stuck ‘restoring’

try this…

 

RESTORE DATABASE <DATABASE_NAME>

WITH RECOVERY

Advertisements

Restoring Joomla

Edit… think this our CDP knacking the perms

 

When I restore Joomla sites the perms are shot so….

Back up system is CDP

Restoring to cPanel  Cloudlinux

So you restore to public_html

Check connection string by editing configuration.php

Restore db

Set user

add user to db

test site

errror

fix perms

chown -R user:user /home/user/public_html

chown nobody /home/user/public_html;

Test

should work

if not

keep trying…

 

Export table from database to csv file

From here

http://stackoverflow.com/questions/14212641/export-table-from-database-to-csv-file

From SQL Server Management Studio

 1. Run a SELECT statement to filter your data
 2. Click on the top-left corner to select all rows
 3. Right-click to copy all the selected
 4. Paste the copied content on Microsoft Excel
 5. Save as CSV

Using SQLCMD (Command Prompt)

Example:

From the command prompt, you can run the query and export it to a file:

sqlcmd -S . -d DatabaseName -E -s, -W -Q "SELECT * FROM TableName" > C:\Test.csv

More information here: ExcelSQLServer

Notes:

  • This approach will have the “Rows affected” information in the bottom of the file, but you can get rid of this by using the “SET NOCOUNT ON” in the query itself.
  • You may run a stored procedure instead of the actual query (e.g. “EXEC Database.dbo.StoredProcedure”)
  • You can use any programming language or even a batch file to automate this

Using BCP (Command Prompt)

Example:

bcp "SELECT * FROM Database.dbo.Table" queryout C:\Test.csv -c -t, -T -S .\SQLEXPRESS

More information here: bcp Utility

Notes:

  • As per when using SQLCMD, you can run stored procedures instead of the actual queries
  • You can use any programming language or a batch file to automate this

Hope this helps.

 

(it totally did 🙂 )