Ask a questionAsk a question
 

AnswerSql Server Express Multiple Connection

  • Tuesday, October 20, 2009 5:51 PMMark Gialo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi All,

    I have a C# application that runs on Sql Server. The application has multiple SQLConnections to the same database. When I try to run the application on Sql Express 2005, it does not allow more than 1 SQLConnection.

    Is there anything I can do to fix this?

    Any insight is most appreciated.

    Mark G

Answers

  • Wednesday, October 21, 2009 2:22 AMDan GuzmanMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    SQL Server Express should allow multiple connections.  Is your database perhaps in single user mode?  What error are you getting?
    Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
  • Thursday, October 22, 2009 12:08 PMJian KangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi Mark.

    Could you please elaborate a bit? How do you connect to the database? What is the connection string?

    If the connection string looks as follows, the issue might be caused by user instance.
     
    Data Source=.\SQLEXPRESS;Integrated Security=true; AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;
    
    Please have a look at the Common Issues section in the following document:

    SQL Server 2005 Express Edition User Instances

    The other main issue with user instances occurs because SQL Server opens database files with exclusive access. This is necessary because SQL Server manages the locking of the database data in its memory. Thus, if more than one SQL Server instance has the same file open, there is the potential for data corruption. If two different user instances use the same database file, one instance must close the file before the other instance can open it. There are two common ways to close database files, as follows.

    Alternatively, you can attach the database in SQL Server Management Studio and modify the connection strings as follows so that multiple clients can connect to the same database.
     
    Server=.\ SQLEXPRESS;Database=myDataBase;Trusted_Connection=True;
    
     

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

All Replies

  • Wednesday, October 21, 2009 2:22 AMDan GuzmanMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    SQL Server Express should allow multiple connections.  Is your database perhaps in single user mode?  What error are you getting?
    Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
  • Thursday, October 22, 2009 12:08 PMJian KangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi Mark.

    Could you please elaborate a bit? How do you connect to the database? What is the connection string?

    If the connection string looks as follows, the issue might be caused by user instance.
     
    Data Source=.\SQLEXPRESS;Integrated Security=true; AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;
    
    Please have a look at the Common Issues section in the following document:

    SQL Server 2005 Express Edition User Instances

    The other main issue with user instances occurs because SQL Server opens database files with exclusive access. This is necessary because SQL Server manages the locking of the database data in its memory. Thus, if more than one SQL Server instance has the same file open, there is the potential for data corruption. If two different user instances use the same database file, one instance must close the file before the other instance can open it. There are two common ways to close database files, as follows.

    Alternatively, you can attach the database in SQL Server Management Studio and modify the connection strings as follows so that multiple clients can connect to the same database.
     
    Server=.\ SQLEXPRESS;Database=myDataBase;Trusted_Connection=True;
    
     

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.