problem with DB restore from VC++!!
Hi,
I have this scenerio:-
1) The Sql server has database mydb. Server can be remote or local. The problem is when it's remote so will mention only that case(remote means on LAN ).
2) I have a app which allows user to back up and restore mydb.
3) If the user wants to restorte the Db he is shown windows common file open dialog box, the user selects the file from some location and hit open.
4)this location could be on the server or the machine running the app. Now if the file is on server everything goes well, but if the file is on the machine running the app SQL Server comes back with the error saying device error of device offline.
The restore is doen by using a stored proc on the database which basically executes somehiting like
restore datatbase mydb from disk = '\\machinename\driveletter$\......\mydbbkp.dat'
Now I imagine this could be due to the fact that the server might not have access to the machine running the app. Is there a way to overcome this hurdle??
Please help!! Have worked too long on all this to be stuck at this thing.
Thanks
Re: problem with DB restore from VC++!!
For SQL Server(or any other app) to access the remote file, you would need to have a drive$ share.
Let us say on machine m1, i have a file on d:\Folder1\mydata.bkp
if i need to access this data from another machine m2, I cannot use the UNC
\\m1\D:\Folder1\mydata.bkp unless there is a $ share on the d drive
Or if folder1 is shared, then i could use \\m1\folder1\mydata.bkp
I think your best bet is to temporarily share the folder, run the restor, then unshare the fodler.
Hope this helps.
Re: problem with DB restore from VC++!!
thanks! yeah that would solve the problem, but how do I create a temporary share?
Is there a way in code to do that?
Re: problem with DB restore from VC++!!
Simplest way would be to run net share <your params> using shellex.
Re: problem with DB restore from VC++!!
well i already had implemented oit using sharing api.
I use netshareadd to do this.
but there is a problem with this.
The share is created fine with all access.
but it does not work.
It works if i right click on the share and got to security tab and add everyone to the list and provide evreyone full control.
I went through documentation of netaddshare but it does not provide any hints how to do this in code.
does anyone has any idea how to do this in code??