Calling sqlcmd from stored procedure without credentials - stored-procedures

I have a stored procedure under SQL Server 2012 Standard which makes calls to sqlcmd through xp_cmdshell in order to execute script files against the database. This always worked fine without passing credentials and without the -E option. Now, under the current version of SQLExpress, I get an error saying "Authentication failed for 'mydomain\mymachine$'" when calling sqlcmd from the stored procedure. It seems that under SQL 2012, sqlcmd is called in the context of either NT Service\MSSQLSERVER while in SQLExpress 2019, it is called in the context of the local machine, although the service is running under NT Service\MSSQL$SQLExpress. Adding the -E switch to sqlcmd does not help, creating a login for the local machine account doesn't help either. Any idea how I can get this to work without having to specify an account and a password for sqlcmd?

I forgot to specify the server instance with the -S switch. On the previous server, there was only a default instance of sql server, so this was never an issue. But on my test machine, there is a default instance + an instance of SQLExpress. So sqlcmd was trying to connect to the local standard instance instead of the SQLExpress instance.

Related

Cannot connect to SQL Server 2014 due to an error

I want to install SQL Server on my machıne whıch has Windows 10 operating system. When I use SQL Server Management Studio to connect to SQL Server, then I get this error:
I make firewall settings. And the server is running now as follows.
How can I fix this error ?
It appears that your "SQL Server (MSSQLSERVER)" default instance is stopped - so therefore you cannot connect to . or (local).
You do have a "SQL Server (SQL2014)" instance up and running, so try using .\SQL2014 or (local)\SQL2014 for connection ....
You need to use .\SQL2014 and not just SQL2014 ..... the syntax is either just machinename, or then machinename\instancename -so if your instance is SQL2014, you need to use .\SQL2014 (or machine\SQL2014) to connect to it.
You're using SQL2014 which means, SQL Server is searching for a server machine by the name of SQL2014 and trying to connect to its default instance - which obviously fails.

Can't connect to a firebird server on docker

I'm a macOS user and I got weird errors just to create a database with firebird. I saw that there are some dock containers with firebird that run just fine ( i was able to create databases, perform queries and so on) but when I tried to connect from my local ISQL or razorSQL client ( through JDBC), I get some weird errors like "unavailable database" or "can't open file"
I'm also not sure how ISQL CONNECT string really works because every site I saw there is a different one.
I got this docker image: ( https://hub.docker.com/r/jacobalberty/firebird/)
I created my container like this:
docker run -d --name firebird -p 3050:3050 -v /data/firebird/databases:/databases jacobalberty/firebird:2.5-ss
my docker-machine IP is:
192.168.99.100
I tried to connect like this:
CONNECT '0.0.0.0:3050://databases/test.fdb' user 'SYSDBA' password 'masterkey';
unavailable database
And also like this:
CONNECT '192.168.99.100:/databases/test.fdb' user 'SYSDBA' password 'masterkey';
connection rejected by remote interface
CONNECT '192.168.99.100:3050:/databases/test.fdb' user 'SYSDBA' password 'masterkey';
Statement failed, SQLSTATE = 08001
unavailable database
When i enter the docker container, the file is there:
root#e4212b9f9d16:/databases# pwd
/databases
root#e4212b9f9d16:/databases# ls
test.fdb
Also, I'm not sure how to check if the firebird server is running ( i guess it is cause I can 'connect' to a database inside the container'.. but the docker container is definally up and running - did a successful telnet on the ip and port)
I also tried to use the container IP (172.17.0.2) but i got a timeout
Im most familiar with mysql and SQLite never touched a firebird db before and as the user got this DB, i have to mock it, develop an app using fake data and then connect it to the real firebird (so changing the DB is not an option)
So, the standard documentation about 'create your firebird server' don't mention but you on firebird.conf, the variable RemoteBindAddress must be empty
File:
/etc/firebird/2.5/firebird.conf
Lines changed:
RemoteBindAddress =
#RemoteBindAddress = localhost
Thanks for all the
Most of your problems are your connection string, it should be <host>/<port>:<database-path-or-alias>, where leaving of /<port> will default to port 3050.
This accounts for all your problems except for
CONNECT '192.168.99.100:/databases/test.fdb' user 'SYSDBA' password 'masterkey';
connection rejected by remote interface
As that connection string is a valid one.
This error means that you were able to connect to the server, but the connection was rejected. This might - for example - happen when you use Firebird 3, but connect using a Firebird 2.5 ISQL/fbclient library, and haven't relaxed the security settings of Firebird 3 (see Legacy Authentication in the Firebird 3 release notes).
In order to find out if the server is running, use:
docker ps
In order to figure out if the server actually started, or errored out upon start, start the container without the -d and look at the log messages when it runs:
docker run --name firebird -p 3050:3050 -v /data/firebird/databases:/databases jacobalberty/firebird:2.5-ss

Connecting to LocalDB from Visual Studio Online Build Server

I have a library project that has a local MDF file (LocalDB) and uses the following connectionstring:
Data Source=(LocalDb)\v11.0;Initial Catalog=MyDB;Integrated Security=True
The code needs to access the DB in compilation time (F# Type Provider). It works fine locally but it fails when it is compiled on the Visual Studio Online Build Server (TFS) with the following error:
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=26085; handshake=248;
I checked and it looks like LocalDB is installed on the build servers: http://listofsoftwareontfshostedbuildserver.azurewebsites.net/
Any ideas? Do I need special permissions to access LocalDB?
Thanks!
I had a similar problem and I solved it by initializing LocalDb in a post-build event. You might need to put it in a pre-build event if your build itself is accessing the database.
I wanted to have a dynamic LocalDb database created every build in order to access it from my unit test suite. I decided to use the RimDev.AutomationSql package to allow my unit tests to programmatically create the LocalDb instance rather than checking in a .mdf file. (See http://www.nuget.org/packages/RimDev.Automation.Sql/)
According to the RimDev.Automation.Sql github readme, https://github.com/ritterim/automation-sql, even though LocalDb is installed, it may not be initialized.
You may have LocalDB installed, but never initialized the instance on
your machine. Run this command via command prompt.
LocalDB SQL Express 2014
"C:\Program Files\Microsoft SQL Server\120\Tools\Binn\SqlLocalDB.exe"
create "v12.0" 12.0 -s
LocalDB SQL Express 2012
"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SqlLocalDB.exe"
create "v11.0" 11.0 -s

Rails with unixODBC and SQL Server 2000 and FreeBSD

I'm having a problem trying to deploy a Rails application
a FreeBSD server, I am using unixODBC and FreeTDS to
access the database that sits on a server with windows server
Sqlsever 2003 and 2000.
The problem is that the application can only access the database
when using the SA user sqlserver, when I try to use another user,
the application can not access. But when I test the DSN created outside
the application I can access the database with other users,
DSN using the same application.
Does anyone have an idea what might be? Ja I even put the
I created user to access the application with all rights ..
db_owner .. and so on .. and still can not access when I try to run
application with this user.
tanks!
:) Alessandra
I realized that if I omit the user or placing a user who does not exist, but the password being the same as in SA it connects too.

Firebird error "username and password are not defined" with Delphi application

I have an application made with Delphi 2006 and Firebird 2.5. For connection a use Interbase components from Delphi. I setting up in design time a TIBDatabase with username, password tc, and work ok, but when i want to run application in another pc (first i install Firebird 2.5 on it), i received this error:
Statement failed, SQLSTATE = 28000
Your user name and password are not defined. Ask your database administrator to set up a Firebird login.
What is this? How can I resolve that?
The message clearly states the username and password you're using to connect at design time in your development machine are not valid to the database server you're trying to connect on the other machine (let's call it production). From your message it seems it is not the same server you connect to at design time.
I suggest you to test this issue with ease to put the LoginPrompt property to true on the TIBDatabase component to allow it to ask the user for propper credentials before connecting. You will be able to connect using any valid username/password combination for that server. To be sure the combination are valid, try to connect using the isql command line tool, for example the command
c:\test>isql test.fdb -u sysdba -p masterkey
will connect to c:\test\test.fdb using default username and password. (the firebird root directory must be in the path environment variable for this to work)
Also, you can use the gsec command line tool to adjust the password for this engine or you can provide the create users and change passwords on that production machine before trying to connect to it.
On Windows, firebird default sysdba password is masterkey.
The solution that finally worked for me on windows was starting cmd.exe as administrator and running "C:\Program Files (x86)\Firebird\Firebird_3_0\gsec.exe" -user sysdba -password masterkey -mo sysdba -pw masterkey
This error is because the credentials for Firebird db is simply not stored in the database file. It's stored in the configuration file on the Firebird Server. If you copy over the DB file, and not the password -- you will have a different password.
On Ubuntu machines you can find out the password and username in the file, /etc/firebird/<version>/SYSDBA.password
It'll look something like,
ISC_USER=sysdba
ISC_PASSWORD="password"
Use those credentials to connect to the database file.
At 'isql-fb' from linux terminal and after the 'CONNECT' on database:
- I solved after delete(drop) and recreate the 'SYSDBA' user.
Observation: I had problems with file and folder permission at '/tmp/firebird' and I needed to use 'sudo' or root to open 'isql-fb'
Thanks.
I once got this error trying to connect to a Firebird 3.0.3 database using the Firebird 2.5 client libraries. I just forgot to update the client libraries to 3.0.3. Maybe this will help someone.

Resources