Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i want to ask a question
how can check database online or offline if offline make online
and how can give my program permission to read and write file in my drive
like this code work with me in external driver like flash how can work in my internal hard disk

C#
string filename = textBox1.Text + "\\Issues" + DateTime.Now.ToShortDateString().Replace('/', '-')
 + " - " + DateTime.Now.ToLongTimeString().Replace(':', '-');
           string strquery = "Backup Database Issues to Disk='" + filename + ".bak'";
           cmd = new SqlCommand(strquery, cn);
           cn.Open();
           cmd.ExecuteNonQuery();
           cn.Close();
Posted
Comments
Afzaal Ahmad Zeeshan 25-Sep-15 0:38am    
What do you mean by online or offline? Is there network included somewhere or do you mean to open the connection?

As you are using SQL Server, you can take advantage of SMO (https://msdn.microsoft.com/en-us/library/ms162169.aspx[^]). It is far better than hit-miss.

Here is exactly what you have asked for (in VB, but quite simple to transscribe): https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.database.status(v=sql.120).aspx[^]

Even better, you can use SMO to manage backups without T-SQL. See this article: SQL Server 2008 - Backup and Restore Databases using SMO[^]
 
Share this answer
 
C#
if (SqlCon.State == ConnectionState.Open)
               {
                   //SqlCon.Close();
                   //SqlCon.Open();
               }
 
Share this answer
 
Comments
George Jonsson 25-Sep-15 2:15am    
No variable declarations, no explanation.
Too little information to be a good answer.
Member 11538085 25-Sep-15 10:19am    
i want check database SQL Server online or offline if offline make online

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900