Showing posts with label cant. Show all posts
Showing posts with label cant. Show all posts

Thursday, March 8, 2012

Backup cant find database name

I was trying to backup my database file using My.Computer.FileSystem.CopyFile but because SQL keeps the file locked this doesnt work (I am using VB.NET 2005 Express and SQL 2005 Express). It seems that the Backup command is what I want to do but it doesnt recognise my database name, which otherwise appears in the Database Explorer tab of the IDE

I wrote a function to use the Backup command as follows
Public Sub MyDbBackup()
Dim sqlconn As New SqlClient.SqlConnection(MyConnectionStringdb)
Debug.Print(sqlconn.Database)
sqlconn.Open()
Dim Backupcommand As SqlClient.SqlCommand = New SqlClient.SqlCommand("BACKUP DATABASE MyDatabase TO DISK = 'c:\Mydatabase.bak'")

Backupcommand.CommandType = CommandType.Text
Backupcommand.Connection = sqlconn
Backupcommand.ExecuteNonQuery()
sqlconn.Close()

End Sub

But this gives the error
Could not locate entry in sysdatabases for database 'Mydatabase'. No entry found with that name. Make sure that the name is entered correctly. BACKUP DATABASE is terminating abnormally.

I have also tried with the .mdf extension, with the full path name, and with the name as given by sqlconn.database which is supposed to be the full database name, with and without single quotes surrounding it.

How can I find out which database name this function requires and why it is not finding the database? Other queries on it are working fine.

Thanks

Martin

hi,

the Transact SQL syntax is correct... but this works against "traditional" SQL Server (and SQLExpress) instances... are you perhaps working with a user instance (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsse/html/sqlexpuserinst.asp)?

if this is the case, the database name you see in the IDE (VS ide or SQL Server Management Studio IDE?) is not the same as the registered database name in the running SQLExpress user instance.. the name is composed with the file + path of the .Mdf file the database is composed of..

regards

|||

Andrea Montanari wrote:

hi,

the Transact SQL syntax is correct... but this works against "traditional" SQL Server (and SQLExpress) instances...

should be read as "but this works directly against "traditional" SQL Server (and SQLExpress) instances... user istances modify the database name as reported..

I apologise..

regards

|||Thanks Andrea for the link to the article on User Instances, I was using that method as it was the default method used in the connection string generated by the database wizard, so I did need the full path. But that was not the full story, because I still had problems getting SQL to recognise this database name.
In the end, the correct database name was given in the connection object sqlconn.database but because it had had its first few characters replaced with some sort of unique identifier which started with numbers and an E, the Backup command seemed to think it was a floating point number even though it was expecting a database name at this position in the command. Putting it in single quotes did not work, but after lots of guessing different syntax variations, I tried square brackets and it worked.

For anyone else with this problem, here is the form of my solution:

Public Sub MyDbBackup()
Dim sqlconn As New SqlClient.SqlConnection(MyConnectionStringdb)
sqlconn.Open()
Dim Backupcommand As SqlClient.SqlCommand = New SqlClient.SqlCommand("BACKUP DATABASE [" & sqlconn.Database.ToString & "] TO DISK = 'c:\Mydatabase.bak'")
Backupcommand.CommandType = CommandType.Text
Backupcommand.Connection = sqlconn
Backupcommand.ExecuteNonQuery()
sqlconn.Close()
End Sub|||

Hi, I'm trying to do exactly the same thing as you did. You solution is a great help to me. However, when I modify the sqlCommand for Restore operation, I won't allow me since the database is currently used by my application. Would you tell me how you did that? Thanks.

Public Sub RestoreOperation(ByVal restorePath As String)

Dim sqlconn As New SqlClient.SqlConnection(GlobalConnectionString)

Try

' the command for restoring the DB

Dim cmdBackup As New SqlClient.SqlCommand("RESTORE DATABASE [" & "Test.mdf" & _

"] FROM DISK = '" & restorePath & "'", sqlconn)

sqlconn.Open()

cmdBackup.ExecuteNonQuery()

Finally

sqlconn.Close()

End Try

End Sub

|||

hi,

modify the context of your connection via con.ChangeDatabase or close it and open another one referencing the master system database...

regards

|||

Hi Andrea, thanks for your suggestion. It seems very good to me. However, I have a problem. Since I'm new in ADO.net, I use the most basic solution (drag-and-drop from Data source Explorer) to setup my database. So my program have a bunch of forms and each have their own TableAdapters. So other than closing all the connections from each adapter, is there other way to do it? Can it be done by SQL? Appreciated.

This is my connection string:

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Test.mdf;Integrated Security=True;Connect Timeout=60;User Instance=True

|||

hi,

actually Inever use your approach, thus drag&drop ...but, anyway, all database connections against the database to be restored must be closed before restoring...

regards

|||Yeah, I guess I don't have much choice. Thanks for your reply.

Backup cant find database name

I was trying to backup my database file using My.Computer.FileSystem.CopyFile but because SQL keeps the file locked this doesnt work (I am using VB.NET 2005 Express and SQL 2005 Express). It seems that the Backup command is what I want to do but it doesnt recognise my database name, which otherwise appears in the Database Explorer tab of the IDE

I wrote a function to use the Backup command as follows
Public Sub MyDbBackup()
Dim sqlconn As New SqlClient.SqlConnection(MyConnectionStringdb)
Debug.Print(sqlconn.Database)
sqlconn.Open()
Dim Backupcommand As SqlClient.SqlCommand = New SqlClient.SqlCommand("BACKUP DATABASE MyDatabase TO DISK = 'c:\Mydatabase.bak'")

Backupcommand.CommandType = CommandType.Text
Backupcommand.Connection = sqlconn
Backupcommand.ExecuteNonQuery()
sqlconn.Close()

End Sub

But this gives the error
Could not locate entry in sysdatabases for database 'Mydatabase'. No entry found with that name. Make sure that the name is entered correctly. BACKUP DATABASE is terminating abnormally.

I have also tried with the .mdf extension, with the full path name, and with the name as given by sqlconn.database which is supposed to be the full database name, with and without single quotes surrounding it.

How can I find out which database name this function requires and why it is not finding the database? Other queries on it are working fine.

Thanks

Martin

hi,

the Transact SQL syntax is correct... but this works against "traditional" SQL Server (and SQLExpress) instances... are you perhaps working with a user instance (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsse/html/sqlexpuserinst.asp)?

if this is the case, the database name you see in the IDE (VS ide or SQL Server Management Studio IDE?) is not the same as the registered database name in the running SQLExpress user instance.. the name is composed with the file + path of the .Mdf file the database is composed of..

regards

|||

Andrea Montanari wrote:

hi,

the Transact SQL syntax is correct... but this works against "traditional" SQL Server (and SQLExpress) instances...

should be read as "but this works directly against "traditional" SQL Server (and SQLExpress) instances... user istances modify the database name as reported..

I apologise..

regards

|||Thanks Andrea for the link to the article on User Instances, I was using that method as it was the default method used in the connection string generated by the database wizard, so I did need the full path. But that was not the full story, because I still had problems getting SQL to recognise this database name.
In the end, the correct database name was given in the connection object sqlconn.database but because it had had its first few characters replaced with some sort of unique identifier which started with numbers and an E, the Backup command seemed to think it was a floating point number even though it was expecting a database name at this position in the command. Putting it in single quotes did not work, but after lots of guessing different syntax variations, I tried square brackets and it worked.

For anyone else with this problem, here is the form of my solution:

Public Sub MyDbBackup()
Dim sqlconn As New SqlClient.SqlConnection(MyConnectionStringdb)
sqlconn.Open()
Dim Backupcommand As SqlClient.SqlCommand = New SqlClient.SqlCommand("BACKUP DATABASE [" & sqlconn.Database.ToString & "] TO DISK = 'c:\Mydatabase.bak'")
Backupcommand.CommandType = CommandType.Text
Backupcommand.Connection = sqlconn
Backupcommand.ExecuteNonQuery()
sqlconn.Close()
End Sub|||

Hi, I'm trying to do exactly the same thing as you did. You solution is a great help to me. However, when I modify the sqlCommand for Restore operation, I won't allow me since the database is currently used by my application. Would you tell me how you did that? Thanks.

Public Sub RestoreOperation(ByVal restorePath As String)

Dim sqlconn As New SqlClient.SqlConnection(GlobalConnectionString)

Try

' the command for restoring the DB

Dim cmdBackup As New SqlClient.SqlCommand("RESTORE DATABASE [" & "Test.mdf" & _

"] FROM DISK = '" & restorePath & "'", sqlconn)

sqlconn.Open()

cmdBackup.ExecuteNonQuery()

Finally

sqlconn.Close()

End Try

End Sub

|||

hi,

modify the context of your connection via con.ChangeDatabase or close it and open another one referencing the master system database...

regards

|||

Hi Andrea, thanks for your suggestion. It seems very good to me. However, I have a problem. Since I'm new in ADO.net, I use the most basic solution (drag-and-drop from Data source Explorer) to setup my database. So my program have a bunch of forms and each have their own TableAdapters. So other than closing all the connections from each adapter, is there other way to do it? Can it be done by SQL? Appreciated.

This is my connection string:

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Test.mdf;Integrated Security=True;Connect Timeout=60;User Instance=True

|||

hi,

actually Inever use your approach, thus drag&drop ...but, anyway, all database connections against the database to be restored must be closed before restoring...

regards

|||Yeah, I guess I don't have much choice. Thanks for your reply.

Friday, February 24, 2012

Backup across the Network

We are using SQL2000
Can I do a database backup onto a file on another server?
In Enterprise Manager, I can't seem to specify a device on another server.
Thanks for any help.
Yes. Just type a UNC name.
Note: SQL must be running under a domain-level account with FULL CONTROL
rights to the share and underlying folders. Don't use administrative
(C$,D$, etc) shares.
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"dschrier" <anonymous@.discussions.microsoft.com> wrote in message
news:72E05DAF-E254-4B13-926B-D183E9E95EAD@.microsoft.com...
> We are using SQL2000
> Can I do a database backup onto a file on another server?
> In Enterprise Manager, I can't seem to specify a device on another server.
> Thanks for any help.
|||First create a backup device that points to a network share on the other
server, than backup to that backup device.
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"dschrier" <anonymous@.discussions.microsoft.com> wrote in message
news:72E05DAF-E254-4B13-926B-D183E9E95EAD@.microsoft.com...
> We are using SQL2000
> Can I do a database backup onto a file on another server?
> In Enterprise Manager, I can't seem to specify a device on another server.
> Thanks for any help.
|||Hi,
Can I do a database backup onto a file on another server?
Yes , follow the below steps. Enterprise manager will only show the local
disks.
There are Few Pre requisites to do backup remotely;
1. You Should start SQL server using Domain user who got access to remote
machine Share
2. Should have share in the remote machine
3. If you need to schedule this as a job then SQL Agent should use the same
Domain user in which SQL server was started
4. Restart the services
Now you can execute the Backup script with UNC path
BACKUP Database <dbname> to disk='\\computername\sharename\dbname.bak' with
init
Note:
Backup to remote machine will not work if you start SQL server using Local
system account
Thanks
Hari
MCDBA
"dschrier" <anonymous@.discussions.microsoft.com> wrote in message
news:72E05DAF-E254-4B13-926B-D183E9E95EAD@.microsoft.com...
> We are using SQL2000
> Can I do a database backup onto a file on another server?
> In Enterprise Manager, I can't seem to specify a device on another server.
> Thanks for any help.
|||Hi ,
Just to add this you can map the remote share on you database server .
The mapped drive can be used to backup on .
Thanks
Ajay
"Hari Prasad" <hari_prasad_k@.hotmail.com> wrote in message
news:ObmCswLSEHA.904@.TK2MSFTNGP12.phx.gbl...
> Hi,
>
> Can I do a database backup onto a file on another server?
> Yes , follow the below steps. Enterprise manager will only show the local
> disks.
> There are Few Pre requisites to do backup remotely;
>
> 1. You Should start SQL server using Domain user who got access to remote
> machine Share
> 2. Should have share in the remote machine
> 3. If you need to schedule this as a job then SQL Agent should use the
same
> Domain user in which SQL server was started
> 4. Restart the services
> Now you can execute the Backup script with UNC path
> BACKUP Database <dbname> to disk='\\computername\sharename\dbname.bak'
with[vbcol=seagreen]
> init
> Note:
> Backup to remote machine will not work if you start SQL server using Local
> system account
> Thanks
> Hari
> MCDBA
> "dschrier" <anonymous@.discussions.microsoft.com> wrote in message
> news:72E05DAF-E254-4B13-926B-D183E9E95EAD@.microsoft.com...
server.
>

Sunday, February 12, 2012

Backup

How can I see the backup with the tools log explorer because I can′t open
this log. ldf?Did you mean to ask, how third party tools are able to read the log files,
while you are not able to read them? These log files are stored in a
specific format, and the thirdparyt tools understand that format. So they
are able to read the log records and present them to you in a readable
format.
You could also use undocumented commands like DBCC LOG to query the
transaction logs.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"newone" <newone@.discussions.microsoft.com> wrote in message
news:997A96C4-31A8-4E1B-B446-B63B99B9C0FC@.microsoft.com...
How can I see the backup with the tools log explorer because I cant open
this log. ldf?