Options

SQL Express Login Issues

eyekroneyekron Posts: 13
edited November 11, 2006 11:46AM in SQL Toolkit Previous Versions
I'm trying to connect to a local copy of a SQL Express database like this:

db1.Register(new rgSQLce.ConnectionProperties(LocalServer, LocalDatabase), rgSQLce.Options.Default | rgSQLce.Options.IgnorePermissions | rgSQLce.Options.IgnoreUsers | rgSQLce.Options.IgnoreUserProperties); //Local DB


Where LocalServer is the name of the SQL Express Instance and LocalDatabase is the path and name of the MDF file.

However, when I try to do this I get this error:

SqlException was unhandled:

Cannot open database "C:\temp\test.mdf" requested by the login. The login failed. Login Failed for user 'MYCOMP\test'.

If I use the sql management server I can attach to it without any problems. No password or user name. If I add the mdf to a project I can access the data in the tables without the need of a username or password.

What am I missing?

Comments

  • Options
    Hello,

    SQL Bundle (including Toolkit) support only connecting to live SQL Server data sources, or loading snapshot files from disk. You cannot directly open an MDF file using SQL Toolkit.

    One possible workaround is to auto-attach the MDF file to the SQLEXPRESS instance.
    ...New ConnectionProperties("BRIAN\\SQLEXPRESS;AttachDBFileName=c:\\temp\\mydb.mdf", "MyDatabase")...
    
  • Options
    This work around works well! Thank you!
  • Options
    My sync code is in my main application as a module. This main application is used to make edits to the local sql express database. If I've been adding, updating, and deleting in my auto connected local copy and then I try to execute the sync process (structure and data), I get this error:

    Unable to open the physical file "C:\Test\AdminApp\bin\Debug\Data\test.mdf". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)".
    Cannot open database "C:\Test\AdminApp\bin\Debug\Data\LCP.mdf" requested by the login. The login failed.
    Login failed for user 'MYCOMP\test'.

    I know that this is because open connections linger, and will not auto close for about 10 minutes. Is there any way to force a close of all open connections before I attempt to execute the sync?
  • Options
    Hi,

    I'm not sure about this. What I suspect is that in your module code, you are trying to open the MDF file directly. The problem with that would be that as long as the MDF is attached to SQL EXPRESS, the SQL Express data engine will probably have an exclusive lock on the file.
Sign In or Register to comment.