Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Cannot access a file between 2 laptops

Author  Topic 

BradH
Starting Member

6 Posts

Posted - 2012-08-24 : 00:01:44
I am trying to share an mdf file between two laptops connected via an ethernet connection. The environment is: Main laptop is called "BandMJ-PC" and the "Slave" laptop is called "BRAD-LAPTOP". I want the Main laptop to be running a particular application accessing ALAMEIN.mdf while the Slave laptop is running a different application also accessing ALAMEIN.mdf on the Main laptop. Both apps are written in vb 2010 Express. So far I have introduced a login for "BandMJ-PC\Guest" in SQL Server Management Studio and given that login full access to the folder containing the data files.
My connection string is:
"Data Source=BandMJ-PC\SQLEXPRESS;AttachDbfFilename=Y:\Test Auctions\ALAMEIN.mdf;Integrated Security=True;User Instance=False"
Where "Y" is the Network drive for the Main laptop.
When I run the application on the Slave I get "An attempt to attach an auto-named database for file "Y:\Test Auctions\ALAMEIN.mdf failed. A database with the same name exists, or specified file canot be opened, or it is located on UNC share."
I have spent days trying to google a solution but there seems to be a huge amount of solutions but I've yet to find one that works for me.
Any help would be greatly appreciated.

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-08-24 : 04:21:38
When sql server is running it locks the files - yoou can't have two versions running on the same files at the same time - and just as well otherwise you would corrupt the database.

You probably need to connect to sql server on the main laptop from the application on the slave - i.e. just have one copy of the database engine running on the main laptop providing services.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

BradH
Starting Member

6 Posts

Posted - 2012-08-27 : 01:23:53
Thank You Nigel for the response. With the connection string "Data Source = BandMJ\SQLEXPRESS; etc" I though I was connecting to the sql server on the main laptop. What am I missing?
Thanks again
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-08-27 : 04:41:02
That would but you are telling it to attach the file. The server needs to be already up and running and you connect to the server - actually form both laptops.

So yoou start sql server on the main laptop - yoou shoouldn't need to attach the file the database will already be there unless yoou detach it. Then you can connect from either laptop as long as the network is set up properly.

It's not like access where yoou open a file - the server is always running waiting for connections.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

BradH
Starting Member

6 Posts

Posted - 2012-08-29 : 00:18:00
I am probably not expressing myself well. I have the mdf file on the main laptop and I am trying to access this mdf file via a client laptop using the version of sql server that is located on the main laptop. So as I understand it, the sql server on the main laptop is in control, so I should be able to access the same mdf file from the main laptop using a different application. At this stage I can't get the application on the client laptop to connect to the mdf file on the main laptop. I have removed the firewall on the main laptop, given the client laptop full security access on the folder containing the mdf file on the main laptop.
Thanks again
Brad
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-08-29 : 00:52:34
You have SQL Server Express running on the main laptop. SQL Server is unlike MS Access where you need to attach to the database file. So for both of your laptop (main and client) you don't need to attach the mdf file. Which also means, you don't need to share out the folder on the main laptop. Basically, you only need to specify the data source as hostname\instance in the connection string.

something like
Data Source=BandMJ-PC\SQLEXPRESS;Initial Catalog=myDataBase;Integrated Security=SSPI;

do refer to http://www.connectionstrings.com/ for further information



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

BradH
Starting Member

6 Posts

Posted - 2012-08-29 : 02:46:49
Hello Khtan,
Thank you for replying to my query. I have tried your suggestion and changed my connection string to:
Data Source=BandMJ-PC\SQLEXPRESS;Initial Catalog=Y:\database.mdf;Integrated Security=SSPI" (Where Y is the network drive for this file with respect to the client laptop)
This now creates this error "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found....."
This is driving me bonkers.
Thanks again for your help
Brad
Go to Top of Page
   

- Advertisement -