RE: Atteched DB's only "read only"
- From: MattHHDE <MattHHDE@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 10 Aug 2006 02:30:01 -0700
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
.
- Follow-Ups:
- RE: Atteched DB's only "read only"
- From: Jaaved Mohammed
- RE: Atteched DB's only "read only"
- References:
- RE: Atteched DB's only "read only"
- From: Jaaved Mohammed
- RE: Atteched DB's only "read only"
- Prev by Date: Re: JDBC and Virtual Machines
- Next by Date: Re: JDBC driver for SQL server 7.0
- Previous by thread: RE: Atteched DB's only "read only"
- Next by thread: RE: Atteched DB's only "read only"
- Index(es):
Relevant Pages
|
Loading