Problem conecting to the same DB from two applications

Hello,

I'm new to VB and SQL server. I have a windows forms application and a Web application that need to connect to the same database (Named WebCenter). But when I try to connect to it from the Web app while running the windows forms app this error message apears:

Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\WebCenter_Data.MDF". Operating system error 32: "32(The process has no access to the file because is being used by another process).
Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\WebCenter_Log.LDF". Operating system error 32: "32(The process has no access to the file because is being used by another process.)".
Cannot open database "WebCenter" requested by the login. The login failed.
Login failed for user 'CARLOS-PC\ASPNET'.
File activation failure. The physical file name "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\WebCenter_Log.LDF" may be incorrect.

Can anyone give me hand or point me in the right direction.

Thanks,

Carlos.

Pd. Please excuse my english.





Answer this question

Problem conecting to the same DB from two applications

  • Fabrizio Valenti

    Carlos...

    Pudiste resolver el problema de conectar a una misma base de datos mediante dos aplicaciones distintas .

    Yo tengo el mismo problema y no tengo idea de que hacer para salirme de esto.

    Saludos.

    Alfredo Martinez

    alfredo_mmarin@msn.com


  • Santos Raphael

    Hi,

    I have the same problem.

    1. I have a web app connecting to the same database as a windows service app.

    2. Every app connects succesflly to the database if the other app is not running

    3. I both app are connecting to the database I get the error message (from the app which connects the second)

    4. The connection string is Data Source=.\SQLEXPRESS;Initial Catalog=ASPNETDB1;Integrated Security=SSPI;Connect Timeout=30

    5. I'm connecting with SqlConnection from the app

    6. I cannot use User Instance because the windows service app is written in VS.2003 and I get an error if the connection string contains User Instance

    Thanks for any suggestion,

    Dana


  • SerenusZeitblom

    Thanks Dana,

    this solved all my problems!
    Here's a good link for those who need an introduction into using Configuring DB's and Accessrights in SQL Server Management Studio- It helped me a lot!

    http://imar.spaanjaars.com/QuickDocId.aspx quickdoc=395

    Cheers,

    Felix


  • davidhov

    OK, something in there worked!

    Thanks for your help!

    I did all the steps except in step 4 there is no IP Addresses Tab;

    so I didn't set the Ports (I do have sql2005 installed also; I'm using SQL Express because I'm developing a winforms app I want to redistribute.)

    With all the configuration necessary, is SQL Express really a viable component for distribution in an installation program with a winforms app Is it possible to configure it correctly for the install so people don't have to do anything but run my program

    I can't find reasonable good documentation on packaging sql express with a winforms app regarding configuration.

    Thanks again for your help.



  • SteveL26070

    I've got the same problem with an SQL Express db;

    This is a winforms application so it doesnt have anything to do with aspnet;

    I can run my winforms app with no other connections open;

    or I can open the db in sql management studio and alter tables, whatever.

    or open codesmith and do whatever i want to the db;

    but I can only do one of these things at a time;

    if I have the db open in sql management studio, I get a cannot access the default user db error in any other app I'm trying to pen; if I have the db open by using vs studio in debug mode, but try to open it in sql management studio, I get the erorr in this thread saying it can't open the physical database because it can't find it (very strange; it hasn't moved!).

    Any ideas



  • Bogdan Maxim

    Hi,

    1. Do not connect with connection strings which contains AttachDB or UserInstance keyword

    2. You have to attach the database before using the connection string using SQL Server Management Studio Express

    3. From SQL Server Surface Area Configuration must be configured to accept both TCP/IP and named pipes connections

    4. In SQL Configuration Manager you have to enable TCP/IP in Protocol for SQLExpress area. At IP Addresses tab you have to set TCP Dynamic Ports to 0. At TCP Port you have to set a port, by default 1433 if you do not have another SQL Server on this machine.

    5. After that restart the SQL service

    6. The users must have login in the database

    7. I used the following connection string:Data Source=.\SqlExpress;Initial Catalog=databasename;Integrated Security=SSPI;Connection Timeout=30

    I hope this was helpful


  • Peter Gvozdjak - MSFT

    Hi Dana... !!

    Did you solve the problem about connecting to the sam DB from two different applications . I am stuck on this and I do not have any idea to get around on this problem.

    Thanks

    Alfredo.

    alfredo_mmarin@msn.com


  • Bill Guenthner

    A couple things to check:

    • Does the ASPNET user actually have permissions to the directory where the database is located
    • Is the database actually in the directory listed in the error
    • How are you connecting to the database in your code
    • Are you trying to use User Instances
    • Do you have the same problem when attempting to run the Windows app while the Web app is already running and connected to the database
    • Have you confirmed that the Web app can connect successfully when the Windows app is not running

    The error you're getting seems like a permissions error.

    Regards,

    Mike Wachal
    SQL Express team

    ----
    Check out my tips for getting your answer faster and how to ask a good question: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=307712&SiteID=1



  • Problem conecting to the same DB from two applications