DB2 Sample Database unable to create - database

I tried creating the db2 sample database using both DB2 First Steps GUI option "Create sample database" error:
Creating database "SAMPLE" on path "C:"...
Existing "SAMPLE" database found...
The "-force" option was not specified...
Attempt to create the database "SAMPLE" failed
'db2sampl' processing complete.
When I try the "db2sampl" command on the DB2 CLP, I get this error:
Creating database "SAMPLE"...
Existing "SAMPLE" database found...
The "-force" option was not specified...
Attempt to create the database "SAMPLE" failed.
'db2sampl' processing complete.
Furthermore, I have double checked that my DB2 instance was started with "db2start" which returns:
SQL1026N The database manager is already active
which indicates that the instance is indeed started.
I verified that sample was not created with "db2 list database directory" which returned:
SQL1057W The system database directory is empty. SQLSTATE=01606
which shows that no databases have been created and discredits the possibility of the DB2 sample database creation failing because an existing one is present.
What is causing the sample database to fail?

Probably the database was created but uncataloged, that is the reason you do not see the database in the database directory, but the database files and tablespaces still exist.
You can try to recatalog the database and then, drop it if you want to recreate the sample database.
db2 catalog database sample
db2 drop database sample
db2sampl

Related

SSIS Access Database - Need to empty table on my destination Access Database table before inserting new records

Task:
Transfer data from SQL Server into Access Database
Issue:
How to empty my Access destination table before I run the data flow?
I tried to use an Execute SQL Task to run a TRUNCATE command similar to SQL Server, but it seems not working with Access Database?
Thanks in advance!
You can use Execute SQL Task to query a Microsoft Access Database, but you cannot use a Truncate command since it is not supported, you have to use a DELETE FROM ... command.
The following screenshots show an example of the OLE DB Connection manager, and the Execute SQL Task configuration:

Recover deleted data from SQL Server

How can I retrieve deleted data from a table in an SQL Server Database with full recovery model?
To Recover the deleted SQL Data first repair the error that caused the error.
Open DB Browse for your Database
Click on Execute SQL tab
In the console type the command 'PRAGMA integrity_Check' and click on the Play button
Once it is known the Database is in a consistent state run the command DBCC DBREPAIR to run repair DB files
Rebuild the database with REPAIR_REBUILD option
Now you can easily recover the files in SQL Database.
Recover deleted database in SQL and get your files back.

Error While trying to connect to DB2 SAMPLE database for the First TIme

I want to install DB2 UDW in my machine for learning purpose but I am having a hard time configuring the local instance. Any help would be highly appreciated.
I installed DB2 express edition -c . I have selected all the default choices. I am trying to connect using IBM data Studio 4.1, In the "DB2 first Steps" GUI I have chosen to create SAMPLE Database. I am getting the below error
Creating database "SAMPLE" on path "C:"...
Existing "SAMPLE" database found...
The "-force" option was not specified...
Attempt to create the database "SAMPLE" failed
'db2sampl' processing complete.
I tried connecting from Data Studio using the following options
Database- SAMPLE
Port- 50000
host - localhost
Error I am getting
Explanation:
An attempt was made to access a database that was not found, has not been started, or does not support transactions.
User response:
Ensure that the specified database name exists in the system database directory. If the database name does not exist in the system database directory, either the database does not exist or the database name has not been cataloged. If needed, issue a db2start command and then resubmit the current command.
SQL4499N A fatal error occurred that resulted in a disconnect from the data source.
SQLSTATE: 08004
Problem is I am having zero knowledge in DB2. If I need to run db2start command from where I should run this? Please help
Probably the instance is not started.
Once you have installed DB2, you need to have an started instance in order to use any database. The instance could be created at the same time of the installation. You can verify which instances exist in your computer by issuing:
/opt/IBM/db2/V10.1/instance/db2ilist
The output should give you a set of users, where an instance has been configured.
You can change to that user and start the instance. For example if the user is db2inst1
su - db2inst1
db2start
Once the instance is started, you can now create a database and then connect to it.

What causes "SQL01268: Msg 1834: cannot be overwritten. It is being used by database"? (in Database Project)

Full error below:
Error 1 SQL01268: .Net SqlClient Data Provider: Msg 1834, Level 16, State 1, Line 1 The file 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\testdatabase.mdf' cannot be overwritten. It is being used by database 'testdatabase'. SchemaCompare5 25 0
I read about this on some forums and quite a few people were getting this and supposedly for some it had to do with parameterising the file path name to the db etc. or ticking "ignore file names and path for files and log files" prior to doing the comparison - this I have tried to no avail.
Someone else who has the same/similar issue: http://social.msdn.microsoft.com/Forums/en/vstsdb/thread/5a8b8c52-adb4-4a5a-95ed-09ad22bacf60
Basically for me I seem to get this error irrespective of which databases I am using for target and source. Say even if I create a new database with one table and another database with no tables and different name and try to update the schema of the database with no tables using the db with the single table it still gives me the error. Almost like SQL server express has gone nuts. I remember using the schema comparison tool before with no trouble. All db connections were created, tried many ways to do this to no avail ie: pointing to copy of *.mdf db in another folder or deleting things from the DATA folder in mysql directory in program files etc.
Also believe I read someone had solved a similar issue be deleting some files the scheme
comparison tool creates, think they were *.sql type not sure which ones though.
The problem arises because the database files already exist.
Try the below within the Visual Studio database project.
Create the schema comparison.
Go to menu: Data > Schema Compare > Export to > Editor
Once the script has been created delete the alter database commands that add the physical files. Then create a connection, switch to SQLCMD mode (making sure you have focus on the script) and execute the script.
To switch to SQLCMD mode access: Data > Transact-SQL Editor > SQLCMD Mode
If the target DB already exists, just delete through Management Studio first before you deploy for the first time.
I had already created the database manually through SQL Server Management Studio when I was establishing the original connection when creating the Database Project via the SQL Server 2008 Wizard in VS. It wouldn't allow me to continue until it could detect that the database existed. Then once I got to the Deploy step for the first time, it threw the same error as above. I just went into Management Studio and deleted the DB, then tried to deploy and it worked fine. Interestingly, it's deploying every time now without me having to go in and delete it every time.
RESTORE DATABASE B FROM DISK = 'A.bak'
WITH MOVE 'DataFileLogicalName' TO 'C:\SQL Directory\DATA\B.mdf',
MOVE 'LogFileLogicalName' TO 'C:\SQL Directory\DATA\B.ldf',
REPLACE ---> Needed if database B already exists

Creating ASP.NET Membership Tables Using Tarantino Database Management

I'm introducing Tarantino Database Management into a project, which has a brand new database schema. The only change (located in 0001_InitialSchema.sql) is the creation of the tables used in ASP.NET Membership. I generated the tables using aspnet_regsql.exe and then scripted them as CREATE TO scripts, then combined them into my single Tarantino sql file.
Upon running my NAnt build script, the drop database command chokes when trying to drop all connections from the database it's trying to drop.
Dropping connections for database DBName
[call] An exception occurred while executing a Transact-SQL statement or batch.
[call] Only user processes can be killed.
This causes the following create database step to fail since the database still exists, and no new updates will be applied:
ManageSqlDatabase:
Create DBName on localhost using scripts from path\to\source\src\Database
BUILD FAILED - 1 non-fatal error(s), 0 warning(s)
INTERNAL ERROR
Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: Database 'DBName' already exists. Choose a different database name.
Some system process always remains attached to the database well after the script has run. I've tried running this on different machines and the same problem exists. I've also tried running a different Tarantino project, and it runs flawlessly every time. I even created a dummy update file (which added tables Foo, Bar, etc) which also ran without issues. The problem seems to stem from the CREATE TABLE scripts for the ASP.NET Membership tables.
You can find a copy of the SQL update script run at PasteBin (separated from post due to its length).
That would be a bug in Tarantino aparently. If you look into DropConnections.sql you'll see that the author has fallen for the old myth that any session above 50 is an user session. The correct way to identify user sessions (and thus KILL-able sessions) is to check the is_user_process column in sys.dm_exec_sessions.

Resources