Schedule task in sql express edition using batch file - sql

Requirements - Schedule task in SQL Express Edition.
But SQL server Agent functionality is not available in express edition.
Possible Solution- Schedule batch file execution to execute sql script. Tried
Batch File-cmd /k sqlcmd -i backup.sql
Sql Script-backup database DB_user1212 to disk = 'E:\backups\MyBackup.bak'. But error occurred while executing sql script A network related or instance specific error occurred while establishing a connection to SQL Server
Possible Reason- Something like connection string missing. Help me how to solve this, i am using windows authentication for connection.

All you need to do is add the additional parameters to your call to sqlcmd.
sqlcmd -S yoursqlserver -E -i C:\pathto\backup.sql

Related

How to find SQL Server name in logging in to SQL Server Management Studio

How can I create a server name for database engine in logging in to SQL Server Management Studio?
Or how can I find my default server name? I have been using running SQLCMD -L this code in my command prompt but it turns me nothing it just says Servers:
You can try using Localhost or . to connect to your local instance.
Also, to reattach your database (from the mdf file), you can use the Attach Database command that is showed in the following image.
Hope this helps

Running SSIS package which runs SQLCMD with -E

I have SSIS 2012 package which runs SQL command by executing SQLCMD command line utility with -E switch. This switch means that it should use trusted connection to connect to SQL server.
The problem is that if i try to run package directly through Object Explorer, i get ANONYMOUS LOGON error. I get the same error running package using stored procedures.
The only way i can run it is through SQL Server Agent Job which then uses SQL Server Agent login.
The question is how to run package using stored procedures with some user which will be used for trusted connection?
Two options. For your manual executions, you'll need to use [RunAs][1] command to launch the dtexec process as the desired user. Covered it a bit in this answer Deploying SSIS (SQL Server 2012) Project Outside Network
For scheduled executions, you'll need to create the appropriate stored credentials within SQL Server, authorize those credentials for use with jobs of type SSIS and then create your job using those stored credentials.

restore backup database with out sql server management studio

I have one database backup.
Now i want to install this backup to my friend's system.
His system does not contain SQL Server Management Studio.
How can i install my backup to his system, both are using SQL server 2005.
Statement 1: His system does not contain SQL server management studio
Statement 2: both are using SQL server 2005...
Doesn't the above two statements Contradict each other?
Update Please Ignore my Previous Answer
Run the following Command on Command Promt:
SqlCmd -E -S MyServer –Q “RESTORE DATABASE [MyDB]
FROM DISK=’D:BackupsMyDB.bak(Your backup Databse file)’”
I got the refrence from here
You will need some kind of SQL client on the other computer. As sqlcmd is part of any SQL Server installation that can be used.
Then use the RESTORE (SQL) statement to restore the backup.
Details about the RESTORE statement can be found in the manual: http://msdn.microsoft.com/en-US/library/ms190372%28v=sql.90%29.aspx
You can use any SQL client that is able to connect to the SQL Server on the second computer to run that.
To make things easier, you could use your SSMS instance to let it generate the necessary SQL statement. Just pretend to restore the backup on your computer and use the "Generate Script" dropdown at the top of the dialog to see the SQL that would have been run by SSMS.

How to schedule a script in SQL Server Express ( without SQL Server Agent )?

Ok so I asked a question yesterday about doing a timed procedure. I got some responses about using SQL Server Agent but i found out that I am using Sql server 2008 express RC and its not available.
Here is my first question and I want to know if there is another tool I can use to do a timed procedure with sql server ....thanks again
You can use dialog timers to start activated procedures. This functionality is available on the Express edition. The advantage over an external service, like Windows Scheduler, is that the solution is self contained inside the database. For example you can move the database to a different computer and the timed procedure will still run, on the new computer, once the database is started. An external service requires you to reconfigure the scheduler agent on the new computer.
You can use scheduled task (control panel-administrative tools) and start a .cmd/.bat file where you use sqlcmd to execute SP's or run scripts.
sqlcmd is a command line tool. sqlcmd /? will show you what you can do with it.
Here is how you can use sqlcmd to execute a SP called StoredProcName in database YourDatabase on server instance ComputerName\sqlexpress.
sqlcmd -S ComputerName\sqlexpress -E -d YourDatabase -Q "exec StoredProcName"
Read more about Using the sqlcmd Utility here http://msdn.microsoft.com/en-us/library/ms180944.aspx
Read about the Task Scheduler here http://msdn.microsoft.com/en-us/library/aa383614%28v=vs.85%29.aspx.

how to start SQL Server 2008 service from command prompt?

i want to start the Microsoft SQL Server 2008 services from command prompt.
how can i achieve through command prompt?
Check here
On top of that here is how you can Manage SQL Server Services from the Command Line which may be more relevant to what you are after.