vbnetskywalker 0 Newbie Poster

hi guys
lately I've been experiencing LinqToSql + Sql Server Express 2005, and it was a great journey (muddy)
anyway .... I'm at the point that I want to make a Backup/Restore for the database

backup for SSE is as easy as a simple copy paste of the mdf file,
but the problem that I can't copy the file while the server is using the file,
server doesn't let the file go untill the app is closed or after about 4 - 6 minutes of idle time, while the file is not in use)

so I have to do it the hard way
(I hope there is some way enables me doing the simple copy paste without going through the hard way)

not even the hard way was good for me
so I need your help guys

the Backup went normal by executing the TSQL on the DataContext,

but the Restore: I tried many ways, but failed......

we can't execute Restore on the same database
we need to use the Master or other database which I failed accomplishing by executing "User Master" on the DataContext either , ........

I really don't want to use the SqlBulkCopy (come on......, I'm using SSE)

so I went to SMO
I tried the next code
(code in my project doesn't look like this,.... I was just testing some thigs, to get an idea, cuz it really needs to get optimized)

Dim db As PhoneBookDC = PhoneBookDC.GetDC
        Dim conbldr As New SqlConnectionStringBuilder(db.Connection.ConnectionString)
        Dim user = db.ExecuteQuery(Of String)("select current_User").FirstOrDefault
        Dim DBName = db.ExecuteQuery(Of String)("select Db_Name()").FirstOrDefault
        Dim SrvrName = db.ExecuteQuery(Of String)("select @@ServerName").FirstOrDefault
        MsgBox(SrvrName & vbCrLf & conbldr.DataSource) 'these differ in my project, is it common ?        
'----try 2 connect 2 Server 2 do Backup/Restore ------        
Dim srv1 As New Server(conbldr.DataSource)
        MsgBox(srv1.Databases.Contains(DBName)) 'my db is not in here
        Dim srv2 As New Server(SrvrName) 'this doesn't even connect
        MsgBox(srv2.Databases.Contains(DBName)) 'Error : "Failed to connect to server [SrvrName]"

a lot of things are going on .....
more than one question are here :
why there are two names of servers while I have only one installed ?!!!!! (line number 6)


and I tried to connect to the database "Master" to do the work and the connection worked .... but the problem that evey time I do, I log in as "guest" which doesn't allow me doing the Backup/Restore .....
even when I put the user name "dbo" in the ConnectionString it still connects as "guest"


can any one help me out .......... a link , a book , an article , an advice ....
thanks in advance


any way guys, this is my first post here ..... glad to be part of the family

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.