Stellen Sie eine FrageStellen Sie eine Frage
 

Fragehow to make a .mdf file shareable

  • Mittwoch, 17. Juni 2009 19:13landon1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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

Alle Antworten

  • Mittwoch, 17. Juni 2009 19:15David M MortonMVPTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    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
  • Mittwoch, 17. Juni 2009 19:18landon1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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.
  • Mittwoch, 17. Juni 2009 19:25landon1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Of course the data base is running!!!

    It would be nonsense to expect that the database close down to allow access.

  • Mittwoch, 17. Juni 2009 19:29David M MortonMVPTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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
  • Mittwoch, 17. Juni 2009 19:35landon1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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!
  • Mittwoch, 17. Juni 2009 19:38David M MortonMVPTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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
  • Mittwoch, 17. Juni 2009 19:46landon1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    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
  • Freitag, 3. Juli 2009 19:22landon1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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.
  • Freitag, 10. Juli 2009 22:08landon1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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!)
  • Samstag, 11. Juli 2009 00:24landon1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    I have the exact steps now....right click the project and add a dataset...rest follows

    drag tableadapter onto design

    answer questions...done
    • Tag als Antwort aufgehobenlandon1 Freitag, 24. Juli 2009 19:12
    • Als Antwort markiertlandon1 Sonntag, 12. Juli 2009 21:52
    •  
  • Sonntag, 12. Juli 2009 22:03landon1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    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

  • Freitag, 7. August 2009 19:03landon1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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!