how to make a .mdf file shareable
- I am creating a WPF project to display a table on a grid.
Using Microsoft Visual C# 2008 Express Edition with SP1
I am trying to make a database explorer connection to the .mdf file
I get a message "the process cannot access the file because it is in use by another user."
sql server 10.0.1600 SQLEXPRESS
所有回覆
The mdf is probably attached to a running instance of SQL server. You might want to go to connectionstrings.com to try to find the right connection string to connect to it through SQL server, and not through the file.
David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client- Of Course!
Microsoft Visual C# 2008 Express Edition with SP1
Database Explorer
is requesting a file name! (.mdf).
I have done this in the past without problem. - Of course the data base is running!!!
It would be nonsense to expect that the database close down to allow access. - So in that case, you shouldn't use the Database Explorer from C# Express to connect to the file directly. Unfortunately, C# Express Edition doesn't have a connection dialog that allows a connection to SQL Server Instances. The only dialog it gives is for connecting to a specific file. You'll have to define your connection string to connect to the SQL Server instance directly, and use the Initial Catalog portion of the connection string to indicate the database you want to connect to. You won't be able to connect directly to the file.
string connectionString = "Data Source=instanceToConnectTo;Initial Catalog=DatabaseToConnectTo;Integrated Security=true;"
For more connection strings, check out
http://www.connectionstrings.com/ which is a great resource for this.
Short answer: you'll have to set up the connection manually.
David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client- 已標示為解答Jim Zhou - MSFT版主2009年6月24日 上午 09:56
- 已取消標示為解答landon1 2009年7月24日 下午 07:13
- thanks! I will quote you!
Difficult to believe this state of affairs in view of the fact that .NET has been past beta for 8 years!
I am reading an O'Reilly book "Programming WPF". I'll also look there for a working example!
WPF may never fly! WPF has become part of the problem instead of part of the solution!
I'll check http://www.connectionstrings.com/ as well! Thanks! thanks! I will quote you!
Difficult to believe this state of affairs in view of the fact that .NET has been past beta for 8 years!
I am reading an O'Reilly book "Programming WPF". I'll also look there for a working example!
WPF may never fly! WPF has become part of the problem instead of part of the solution!
I'll check http://www.connectionstrings.com/ as well! Thanks!
This issue has nothing to do with either WPF or .NET. This is SQL Server that has locked the file, and .NET can't go outside the bounds of what the OS has specified with regards to file handles and how many programs can access a file at a time. This is a simple limitation of operating systems and file access, and the problem would even exist on any other OS, such as Unix, Linux, etc.
David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
Of course!
This shareability was no problem in previous versions of .NET.
where I used the database explorer and in fact those programs are still working today
even though the SAME server is running!
Previously... I faintly remember that I did not have to specify a mdf file.
Boils down to "why doesn't the database explorer allow the same working facility?"
That is what it is for!
FIN- Bingo! Pretty sure I solved the problem! I'll be 100% sure tonight!
Here is what I did.
(1) Open a C#.NET Windows Forms Project
(2) add a connection tp a MS SQL Server database
(3) close the project
(4) open a WPF project and open the server explorer tab
(5) I saw a good connection to a MS SQL Server database
all the supporting dataset objects/methods are there!
and opening this connection I can see the table and columns. - I have successfully compiled and run a WPF app that connects to a mdf file under SQL Server 2008.
The SQL Server 2008 server is running with no restrictions.
I used data explorer. I cannot write down the exact steps just now but I can email the project
and necessary SQL for SQL Server 2008(takes 1 minute to create the table!) - I have the exact steps now....right click the project and add a dataset...rest follows
drag tableadapter onto design
answer questions...done code available
anybody needing a working example of WPF connected to a SQLServer 2008 database file.
Some advances will be made
(1) real time access
(2) changes (not yet possible) are reflected in actual database (nearly (1)) in real time
Since I am just learning this stuff, I have to take this one step at a time.
VS2008 and SQLServer 2008 are free- I have success ONLY in using a local copy of the mdf file.
http://blogs.msdn.com/smartclientdata/archive/2005/08/26/456886.aspx
great post...renews my faith in this forum.
gentlemen take note!

