Search   

Tuesday, January 06, 2009

Support » Support Forum

Register  Login

      
 My Posts  
 
SearchForum Home
  NDO-Forum postings in english please, if possible.  Developing with NDO  Open more than ...
 Open more than one database in an application
 
 1/17/2007 9:52:19 PM
Gerhard
11 posts


Open more than one database in an application
Hello, in our application it should be possible to open more than one database at the same time. For that purpose in connection string the database name and path to the database file is changed. An example connection string is: >>>Integrated Security=SSPI;Persist Security Info=False;Data Source=ISTXP028\SQLEXPRESS;Initial File Name=C:\Labtronic Data\tmp\TWRml_ktiziaru\TWRml.mdf;Initial Catalog=TWRml_ktiziaru<<< We using SQL Server 2005 Express and NDO version 1.2 SP1. If a database is opened again (DB was before already open) the application throws an exception: ExceptionType:NDOException Message:Exception of type SqlException while executing a Query: Unable to open the physical file "C:\Labtronic Data\tmp\TWRml_ktiziaru\TWRml_log.LDF". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)". File activation failure. The physical file name "C:\Labtronic Data\tmp\TWRml_ktiziaru\TWRml_log.LDF" may be incorrect. New log file 'C:\Labtronic Data\Tmp\TWR_DBR_z11e3lwu.uvx\TWRml_log.LDF' was created. The Service Broker in database "6" is disabled because there is already an enabled Service Broker with the same ID. Changed database context to 'TWR_DBR_z11e3lwu.uvx'. Changed language setting to us_english. Sql Statement: SELECT [ActuatorFixedProperties].[ID] FROM [ActuatorFixedProperties] The database was opened the first time in "C:\Labtronic Data\tmp\TWRml_ktiziaru\TWRml.mdf" and DB name was "TWRml_ktiziaru". The second time it will be opened in C:\Labtronic Data\Tmp\TWR_DBR_z11e3lwu.uvx\TWRml.mdf with DB name "TWR_DBR_z11e3lwu.uvx". Is there a possibility to close explicit the connection for an open database from NDO or what next can I do to avoid this problem.
 1/18/2007 9:26:04 AM
Mirko
109 posts
5th


Re: Open more than one database in an application

Hi Gerhard,

if I understand you right, your application opens several copies of your database residing in different files. I don't know exactly, what happens there, but I guess, that you run into this problem because of the ADO.NET connection pooling. NDO closes all connections as soon as possible (at least after calling pm.Save()), but the connection may remain open and is put into a connection pool by ADO.NET. Since I'm not in the office today, I can't investigate in this question immediately. My suggestion for you is to look for ways to manipulate the connection pooling for your Sql Server.

I try to investigate in this problem right after I'm coming home and let you know, what I can find out.

Best regards:
Mirko

 1/18/2007 2:19:22 PM
Gerhard
11 posts


Re: Open more than one database in an application
Hi Mirko, thank you for the quick response. I'm not an expert in ADO.NET therefore we use NDO (it makes database programming much simpler). So it would be excellent if you can give me some hints. Regards Gerhard
 1/23/2007 12:37:45 PM
Mirko
109 posts
5th


Re: Open more than one database in an application
 Modified By Mirko  on 1/23/2007 1:40:34 PM)

Hi Gerhard,

good news for you. I tried to do what you described and it works. I did the following:

1. I created a database in Sql Management Studio. In the New Database Dialog you have the possibility to change the path where the database files should be created. Per default they will be created in C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA, where the beginning of the path is the installation directory of Sql Server 2005.
2. I disconnected the database from the Sql Server. Right click at the new database entry, choose "Tasks" and choose "Disconnect" (Trennen). Without disconnecting the database, Step 3 wouldn't work.
3. Using the Windows Explorer I made a copy of the database files (NDOMultitest.mdf -> NDOMultitest2.mdf, NDOMultitest.ldf -> NDOMultitest2.ldf).
4. I wrote the following app:

static string dbName;
static void WriteToDb()
{
    PersistenceManager pm = new PersistenceManager();
    pm.RegisterConnectionListener(new OpenConnectionListener(OnNewConnection));
    // Constructing objects
    SnmpSession sess = new SnmpSession();
    sess.Port = 162;
    pm.MakePersistent(sess);
    //...
    pm.BuildDatabase();
    pm.Save();
}
static void Main(string[] args)
{
    dbName = @"c:\Temp\NDOMultitest.mdf";
    WriteToDb();
    dbName = @"c:\Temp\NDOMultitest2.mdf";
    WriteToDb();
}
static string OnNewConnection(NDO.Mapping.Connection conn)
{
    return "Integrated Security=SSPI;Persist Security Info=False;Data Source=localhost;Initial File Name=" + dbName;
}

As you can see, WriteDb writes into both databases using the same program.

Best Regards:
Mirko

  NDO-Forum postings in english please, if possible.  Developing with NDO  Open more than ...
  SearchSearch  Forum HomeForum Home