Database is in use - Cannot connect to the database with my application - delphi

I am using Firebird 4.0 with SuperServer installed on Microsoft Windows 2011. I am developing a win64 database application with Delphi to access the database file on a remote computer.
If I connect to the database file with IBExpert while I also try to connect to the same database with the application I am developing, I get the following error message:
[FireDAC][Phys][FB]lock time-out on wait transaction
object D:\MYFILES\DATABASE\SZERYNG\IMOVEIS_FIREBIRD\BANCO DE DADOS\DBIMOVEIS.FDB is in use
I can open more than one IBExpert and connect to the same database file but I cannot connect to the database file with my application if any other application like IBExpert is connected to the same database file.
IBExpertFDConnection
IBExpert database registration info
My application's FDConnection parameters
DatabaseDatabase File
D:\MyFiles\Database\Szeryng\Imoveis_Firebird\Banco de Dados\DBIMOVEIS.FDB
D:\MyFiles\Database\Szeryng\Imoveis_Firebird\Banco de Dados\DBIMOVEIS.FDB
Server/ProtocolProtocol
Remote, TCP/IP
TCPIP
Server NameServer
127.0.0.1
127.0.0.1
Port
3040
3040
User NameUser_Name
SYSDBA
SYSDBA
CharsetCharacter Set
ISO8859_1
ISO8859_1
Server Version
Firebird 4.0
SQL Dialect
3
Client Library FileFDPhysFBDriveLink.VendorLib
c:\windows\syswow64\fbclient.dll
c:\windows\system32\fbclient.dll
IBExpert database registration info:
Database File: D:\MyFiles\Database\Szeryng\Imoveis_Firebird\Banco de Dados\DBIMOVEIS.FDB
Server/Protocol: Remote, TCP/IP
Server Name: 127.0.0.1
Port: 3040
User Name: SYSDBA
Charset: ISO8859_1
Server Version: Firebird 4.0
Client Library File: c:\windows\syswow64\fbclient.dll
My application's FDConnection parameters:
Database: D:\MyFiles\Database\Szeryng\Imoveis_Firebird\Banco de Dados\DBIMOVEIS.FDB;
Protocol: TCPIP;
Server: 127.0.0.1;
Port: 3040;
User_Name: SYSDBA;
Character Set: ISO8859_1;
SQL Dialect: 3;
IBAdvanced: set_db_readonly=0;
FDPhysFBDriveLink.VendorLib = c:\windows\system32\fbclient.dll;
My application does not use the embedded Firebird client. How can I solve this problem?

This error can be caused during attach to a database by Database Parameters Block including one of following options: isc_dpb_disable_wal, isc_dpb_set_read_only or dpb_set_db_replica. Former will throw the error unconditionally the rest only if the connection is not alone.
Also an attempt of dropping of the database with more than one connection will result in this error but I don't think that this is the case.

After I have removed from the IBAdvanced parameter of FDConnection the set_db_readonly=0, now my application can connect to the database while IBExpert or any other application is already connect to the same database.
I have included the set_db_readonly=0 parameter in the IBAdvanced parameter of the FDConnection as suggested by the help of FireDAC to set the database as read\write.

Related

TeamCity 9.x Setting up an External Database with unnamed(NULL) MSSQL instance

I'm evaluating TeamCity 9.0.4 and using HSQLDB.
Now trying to setup MS SQL Server 2014 as External Database.I don't have a named instance(NULL).
So I tried the following connection URL
connectionUrl=jdbc:sqlserver://<host>:1433;databaseName=<database name>
connectionProperties.user=<user>
connectionProperties.password=<password>
When I trying to load the build server I'm getting this message.
TeamCity is starting
Continuing attempts to connect to the database
TeamCity server is connecting to MSSQL database. The database server
is not started yet, or the connection properties are not properly set.
And also I checked the log file, this is what I got.
[2015-05-20 14:08:34,513] INFO - jetbrains.buildServer.STARTUP -
Current stage: Continuing attempts to connect to the database
SQLSERVER is up,I think there is a problem with connection URL.
What can I do to solve this.
TeamCity 9.x Documentation Setting up an External Database
Thanks DevOps.
My mistake, I was testing TeamCity locally.
Problem was with the SQL Server Network Connection.
TCP/IP was disabled for SQLEXPRESS
Enable TCP/IP for SQLEXPRESS
Open SQL Server Configuration Manager
Go to Protocols for SQLEXPRESS under SQL Server Network
Configuration.
Right-click on TCP/IP and choose Properties. Set Enabled = YES.
Better check this too, click on IP Addresses tab and find the section
IP All. Set TCP Port to 1433.

Error when trying to create a new local connection in SQL Developer

I just recently installed SQL Developer on Bootcamp, and tried to create a new basic connection with the following attributes:
Connection name: conn1
Username: user1
Password: ****
Connection type: basic, Role: default
Hostname: localhost
Port: 1521
SID: xe
When tested, the error was: Network adapter could not establish the connection, no matter the type of role was given, or the type of authentication. I also tried entering IP as a hostname to replace localhost, and changing port. Still same issue.
Thanks.
Hostname: localhost means that you connecting to your local database, and NOT remotely. For example, i you have created an instance on your laptop. If you have database in the server and just want to connect to it, then put the server hostname.
SID: xe seems to be incorrect at first place. you must provide the correct SID that you provided while creating the instance. Once again, if you are connecting to remote database server, then give the SID of that database you are pointing to.
You have not mentioned the database version. You should try using SERVICE_NAME. For example, in 12c, you connect using SERVICE_NAME.
Use tnsnames.ora to connect to the remote database server. you will find it in $ORACLE_HOME/bin/network/admin/tnsnames.ora make sure it has proper connection and address details.

How to use activerecord-sqlserver-adapter with TinyTDS *and* an Integrated Security connection on Windows *without* saving a password in plain text

I'm trying to use Rails 3.1. with the activerecord-sqlserver-adapter (3.1.1) and tiny_tds (0.4.5) on a Windows machine. In reading about TinyTDS and it's use of FreeTDS it looks like I can use Integrated Security (aka Windows Integrated security/NTLM) by putting a domain-qualified name as the user name (e.g. DOMAIN\userbob). But the docs still want me to type my domain user's password in the database.yml file. That's bad practice because it's insecure and doesn't take advantage of single-sign on, which is part of the point for Integrated Security.
Can I connect without saving a password in plain text in a file? e.g.
developement:
adapter: sqlserver
mode: dblib
dataserver: localhost
database: dev_db
username: DOMAIN\userbob
# password: no_no_please_dont_make_me_type_it_here
But, even if I put a password I get the following error:
TinyTds::Error: Unable to connect: Adaptive Server is unavailable or does not exist
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/tiny_tds-0.4.5-x86-mingw32/lib/tiny_tds/client.rb:60:in `connect'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/tiny_tds-0.4.5-x86-mingw32/lib/tiny_tds/client.rb:60:in `initialize'
I know my server is running and the current user context can connect because this works:
sqlcmd -S localhost -d dev_db -E
Any insights? Is it possible? If not, it should be.
Enable TCP/IP in "SQL Server Network Configuration" in SQL Server Configuration Manager utility.
Then restart SQL Server service.
Regarding security you will need to supply your own credentials otherwise it will use sa account.
Apparently SQL Server 2008 is setup by default to ONLY allow Windows Authentication. To change that you have to open the Management Studio, Right click on your server and select Properties. Select Security and click the "SQL Server and Windows Authentication mode" under Server authentication. This will at least allow you to connect directly to the server until TinyTDS makes the needed changes to allow Windows Authentication.
I think the code making the connection is trying to make the process impersonate the security context supplied by the credentials instead of passing the default credentials through to SQL server.
This would allow you to specify different credentials to the current security context. I've used this trick to connect to a server requiring SSIS from an untrusted domain.
I don't know TinyTDS/FreeTDS, perhaps null or empty credentials would make it use the default security context. Try:
developement:
adapter: sqlserver
mode: dblib
dataserver: localhost
database: dev_db
or
developement:
adapter: sqlserver
mode: dblib
dataserver: localhost
database: dev_db
username:
password:
Try to use
developement:
adapter: sqlserver
mode: dblib
dataserver: localhost\SQLEXPRESS
database: dev_db
username: DOMAIN\userbob
or else do you set 2 variant authentification in your's sql server? then try to connect with sa user...

Rails + SQL Server: what to put in database.yml?

I'm trying to connect Rails to SQL Server. I installed the activerecord-sqlserver-adapter and ruby-odbc gems, but I'm not sure what to put in my database.yml file.
What exactly is a DSN, and why do I need it? (Is this some windows-specific thing?)
What do I do if I want to use Windows Authentication, instead of specifying a username and password?
I tried creating a DSN, specifying Windows NT authentication, and put the following in my config.yml:
development:
adapter: sqlserver
dsn: myDsn
mode: odbc
but I get a "The specified DSN contains an architecture mismatch between the Driver and Application" error. [I tried creating the DSN from Windows/system32/odbcad32.exe as well, since a Google search said this would create a 32-bit DSN instead, but I get the same error.]
Am I missing something in my database.yml file?
UPDATE:
I tried using
development:
adapter: sqlserver
mode:odbc
dsn: Provider=SQLOLEDB; Data Source=.\SQLEXPRESS; Integrated Security=SSPI
but I get a "Data source name not found and no default driver specified" error. Is it possible my Provider is not SQLOLEDB? [I don't know what a provider is or how to figure out what it's supposed to be -- I just copied it from another connection string I found.] I do know that I can connect to .\SQLEXPRESS using Windows Authentication from my actual SQL Server Management Studio program.
A DSN is a "Database Source Name." It contains the information that an ODBC driver needs to connect to a specific database.
Perhaps this SO Q&A will help you: Connect rails application to SQL Server 2005 from Windows
Also see connectionstrings.com for general help with connection strings.

Connect rails application to SQL Server 2005 from Windows

I (sadly) have to deploy a rails application on Windows XP which has to connect to Microsoft SQL Server 2005.
Surfing in the web there are a lot of hits for connect from Linux to SQL Server, but cannot find out how to do it from Windows.
Basically I followed these steps:
Install dbi gem
Install activerecord-sql-server-adapter gem
My database.yml now looks like this:
development:
adapter: sqlserver
mode: odbc
dsn: test_dj
host: HOSTNAME\SQLEXPRESS
database: test_dj
username: guest
password: guest
But I'm unable to connect it. When I run rake db:migrate I get
IM002 (0) [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I'm not a Windows user, so cannot understand really well the meaning of dsn element or so.
Does someone have an idea how to solve this?
Thanks in advance
With Alexander tips now I've modified my database.yml to:
development:
adapter: sqlserver
mode: odbc
dsn: Provider=SQLOLEDB;Data Source=SCADA\SQLEXPRESS;UID=guest;PWD=guest;Initial Catalog=test_dj;Application Name=test
But now rake db:migrate returns me:
S1090 (0) [Microsoft][ODBC Driver Manager] Invalid string or buffer length
Am I missing something?
this is a sample DSN, that connects to the database using the Windows user account (best when corporate network with domain login)
Provider=SQLOLEDB;Data Source=MyServer\MyInstance;Integrated Security=SSPI;Initial Catalog=MyDatabase;Application Name=My Application Name that will show up in the trace
So this uses the OLEDB provider for SQL Server. SQLNCLI can also be used, haven't tried it with ODBC. Actually this DSN isn't quite tested (have to wait for my admin to give me the necessary rights), but it was copied from a working script, that used SQLNCLI as the provider. The Data source is the server, and if it has a named instance, it has to be specified, so it's either just Server or Server\Instance. The Integrated Security=SSPI tells it you want to use Windows Authentication. Otherwise you specify the user and password to use using UID=MyUser;PWD=MyPassword. UID, User, Username, Password - I think all of these parameters work.
There is a great site over the internet that provides all kinds of DSN samples, just can't find it anywhere. If I find it, I will let you know.
If you haven't got any provider in Rails, check out if Rails supports Windows Component Object Model (COM). And if it does, you can even initialize the ADODB.Connection COM class, work with ADO thereon.
Ah, here is that site I was talking about: http://www.connectionstrings.com/

Resources