RE: Atteched DB's only "read only"



Hello

this problem seems to occur only on our MSSQL2005 test system.
When i open the DB with the management tool the DB is marked as read only
and i can read data from the database. Trying the "ALTER DATABASE" command
(ALTER DATABASE DB_154684 SET READ_WRITE") Returns:
Unable to open physical file '...' Operating System error 5: 5(Access Denied)"

Also trying to open the properties of the db in the management console fails
with the error "db is in transition".
The log contains:
2006-08-10 11:15:22.03 spid51 Starting up database 'DB_1155200699343'.
2006-08-10 11:15:22.04 spid51 Error: 17207, Severity: 16, State: 1.
2006-08-10 11:15:22.04 spid51 FCB::Open: Operating system error
5(Access is denied.) occurred while creating or opening file
'D:\bin_eclipse\TempDb\tempDir_1\DATABASE_data.mdf'. Diagnose and correct the
operating system error, and retry the operation.
2006-08-10 11:15:22.04 spid51 Error: 17204, Severity: 16, State: 1.
2006-08-10 11:15:22.04 spid51 FCB::Open failed: Could not open file
D:\bin_eclipse\TempDb\tempDir_1\DATABASE_data.mdf for file number 1. OS
error: 5(Access is denied.).
2006-08-10 11:15:22.04 spid51 Error: 17207, Severity: 16, State: 1.
2006-08-10 11:15:22.04 spid51 FCB::Open: Operating system error
5(Access is denied.) occurred while creating or opening file
'D:\bin_eclipse\TempDb\tempDir_1\database_log.ldf'. Diagnose and correct the
operating system error, and retry the operation.
2006-08-10 11:15:22.04 spid51 Error: 17204, Severity: 16, State: 1.
2006-08-10 11:15:22.04 spid51 FCB::Open failed: Could not open file
D:\bin_eclipse\TempDb\tempDir_1\database_log.ldf for file number 2. OS
error: 5(Access is denied.).
2006-08-10 11:15:22.04 spid51 Error: 928, Severity: 20, State: 1.
2006-08-10 11:15:22.04 spid51 During upgrade, database raised exception
945, severity 14, state 2, address 015891A4. Use the exception number to
determine the cause.
2006-08-10 11:15:22.06 spid51 Starting up database 'DB_1155200699343'.

Reading from the database works fine. Onyl any modification fails.
The files are not read only.


The code is:
/**
* mdf and ldf files are copied to a temp dir, attached, worked with,
detached
* @param f Directory to the database files
* @param dbName desired DB-Name in MSSQL
*/
public static boolean attachDB(File f, String dbName) throws
SQLException {

String sMdfFile=f.getAbsolutePath();
if (f.isDirectory()) {
File[] files=f.listFiles();
int i=0;
for (; i < files.length;i++) {
if (files[i].getName().toLowerCase().endsWith(".mdf")) {
sMdfFile=files[i].getAbsolutePath();
break;
}
}
if (i==files.length) {
//There was no MDF File
return false;
}
}

String sql="EXEC sp_attach_db '"+dbName+"', '"+sMdfFile+"'";
String
ldf=sMdfFile.toLowerCase().subSequence(0,sMdfFile.indexOf("_data.mdf"))+"_log.ldf";
File fLdf=new File(ldf);
if (fLdf.exists())
sql+=",'"+ldf+"'";

Connection con=null;
try {
con=createTemporaryConnection(0);
Statement stmt=con.createStatement();
stmt.execute(sql);
} catch (SQLException e) {
throw e;
} finally {
if (con != null)
con.close();
}

return true;
}

/**
* Creates a temporary connections to the server.<BR>
* <b>This connection is <em>not</em> clossed when a db is closed in app.
* The programmer is responsible to close this connection asap after it
was
* used!
* @param autoClose If n>0, a thread will automaticaly close the
connection after n seconds
* @return A new Connection object
*/
public static Connection createTemporaryConnection(int autoClose) {
Connection con = null;

try {
// System.out.println("DB - OPEN: "+url);
con =
DriverManager.getConnection("jdbc:sqlserver://IBMPC065;instanceName=SQLEXPRESS;", USERNAME, PASSWORD);
con.setCatalog("master");
if (autoClose>0) {
AutoCloseThread thread=new AutoCloseThread(autoClose,con);
thread.start();
}
SQLWarning w = con.getWarnings();

while (w != null) {
LOGGER.warning(w.toString());
w = w.getNextWarning();
}
} catch (SQLException ex) {
LOGGER.log(Level.SEVERE, "Error creating connection for:
(general)", ex);
con = null;
}

return con;
}


Do you have any idea where the error could be?

Thanks in advance!
Matt
.



Relevant Pages

  • Re: Row cannot be located for updating
    ... > result a recordset containing one row, ... > Strangly enough, the value that I changed, is changed in the database ... > Dim Con As New ADODB.Connection ... > 'Execute the query and remove the active connection ...
    (microsoft.public.data.ado)
  • Re: Database connection issue
    ... Dim con As ADODB.Connection 'declare con as a ado database connection ... Private Sub form_initalize ...
    (microsoft.public.vb.general.discussion)
  • Re: anyone help me please...
    ... > text box to the database and display the value? ... > con = new SqlConnection; ... > // this with the current connection. ... > rdr = cmd.ExecuteReader; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: DAO access error w.Ms Access
    ... I can't logged into my database. ... So I tried the visual way, by right clicked on "data connection" in explorer ... workspace file here either. ... >> Dim con As OleDb.OleDbConnection ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Memory Leak in swing application (ImageIcon problem)
    ... private class Person extends Object { ... public void run{ ... java.sql.Connection con = ... I.E you fire your timer, do the random, which opens your connection. ...
    (comp.lang.java.gui)

Loading