I know how to connect using sql auth. But how to use windows auth?
(use 'clojure.java.jdbc)
(require '[clojure.java.jdbc :as j])
(def db {:classname "com.microsoft.jdbc.sqlserver.SQLServerDriver"
:subprotocol "sqlserver"
:subname "//localhost;database=test;user=sa;password=sa"
})
What abount :subname "//localhost;database=test;integratedSecurity=true; ?
reference : http://technet.microsoft.com/en-us/library/ms378428.aspxhttp://technet.microsoft.com/en-us/library/ms378428.aspx#Connectingintegrated
Related
Note - I have never stood up a ruby app like this from the ground up and I am also very unfamiliar with Azure.
I am trying to connect to an existing DB on hosted on Azure via ActiveRecord. I am using ActiveRecord independently of Rails so any convention magic will be unavailable to me. I am currently unable to connect to the database and am unsure if my code configuration is incorrect, if I haven't configured azure correctly, or perhaps my account doesn't have the correct permissions. With my lack of experience I am just unable to determine which is which.
I am currently getting the Login Failed for user '<username>' error from tiny-tds. I've quadruple checked my username and pass and confirmed it is the same credentials I am using to log into the DB from Azure Data Studio. I have also created an app registration from which I got our client id and secret. I'm pretty sure that using the same url for host and resource is not correct but I'm not sure what resource is tbh. With all that said here is my code snippet.
require 'active_record'
ActiveRecord::Base.establish_connection(
adapter: 'sqlserver',
tenant_id: '<tenant_id>',
client_id: '<client_id>',
client_secret: '<client_secret>',
resource: '<servername>.database.windows.net',
active_directory_domain: '<domain> (got this from the primary domain field on the overview screen in azure portal',
host: '<servername>.database.windows.net',
username: '<username>',
password: '<pass>',
database: '<db name>'
)
class IndividualProfiles < ActiveRecord::Base
self.table_name = 'individual_profiles'
end
def run
puts 'Start'
puts IndividualProfiles.first
puts 'End'
end
run
For reference:
activerecord (4.2.11.3)
activerecord-sqlserver-adapter (4.2.18)
tiny_tds (2.1.5)
freetds (v1.3.16)
Not sure exactly what your issue is here (as I do not use all those additional options) however I did notice you are not passing the azure option (which could be the cause of your failure).
There is a configuration in the activerecord-sqlserver-adapter gem specifically for Azure. This is passed through to TinyTDS and without this configuration the connection will not work.
According to the TinyTDS README
TinyTDS is fully tested with the Azure platform. You must set the azure: true connection option when connecting. This is needed to specify the default database name in the login packet since Azure has no notion of USE [database]. FreeTDS must be compiled with OpenSSL too.
My working configurations look akin to:
connection_options = {
adapter: 'sqlserver',
encoding: 'utf8',
pool: 5,
host: '[server].database.windows.net',
database: [DATABASE_NAME],
port: 1433,
azure: true,
timeout: YOUR_TIMEOUT_VALUE,
username: ENV['SQL_USERNAME'],
password: ENV['SQL_PASSWORD']
}
If this does not work please add the following to your post:
Your ActiveRecord version
Your tiny_tds version
Your FreeTDS Version
For Example I have the following working right now: (among other configurations)
ActiveRecord (6.0.4)
tiny_tds (2.1.5)
FreeTDS (v1.00.27 - TDS version 7.3)
I'm developing chat application, I'm using ejabberd for my project. I installed ejabberd server(16.06) successfully and it performing good in auth method as internal. But it is not working when I'm changed auth method as sql. These are the things I'm changed in ejabberd.yml file
default_db: sql
auth_method: sql
## ODBC compatible or MSSQL server:
##
sql_type: mssql
sql_server: "Server=azure_server_name;DSN=DB_Name;UID=azure_DB_username;PWD=azure_DB_password"
sql_pool_size: 10
sql_keepalive_interval: 28800
mod_mam:
iqdisc: one_queue
db_type: sql
default: always
I'm getting following error for while I'm register new user and admin login into web admin portal
ejabberd_auth:is_user_exists:316 The authentication module ejabberd_auth_sql returned an error
when checking user <<"newuser">> in server <<"localhost">>
Error message: {timeout,{p1_fsm,sync_send_event,[<0.390.0>,{sql_cmd,{sql_query,{sql_query,<<"Q9525209">>,#Fun<sql_queries.9.38301790>,#Fun<sql_queries.10.38301790>,#Fun<sql_queries.11.38301790>,{sql_queries,145}}},3534866},60000]}}
I'm used register command:
bin>ejabberdctl register "newuser" "localhost" "password"
Thanks in advance. Please add your ideas and suggestions to resolve this issue.
Again- I am no Ejabberd expert- I imagine someone might have more experience with this; However, it seems that you're confusing Register which I assume is an action to create a login on the Ejabberd platform with the login that is being used on the database. (Or I'm misinterpreting your comments. One of the two.)
You will need to use a username/password combination that exists on the Azure SQL Database in your connection string.
Additionally, you might try the following connection string :
sql_server:"Server=tcp:azure_server_name.database.windows.net;DSN=DB_Name;UID=azure_DB_username;PWD=azure_DB_password"
Has anyone got this working?
I know the docs say that ms sql support is not tested, so I wonder if anyone had it working?
I have enabled the Db module in acceptance.suite.yml
And my credentials in codeception.yml look like this:
modules:
config:
Db:
dsn: 'mssql:host=******.db.8876686.hostedresource.com;dbname=*******'
user: '*******'
password: '******'
dump: app/tests/_data/dump.sql
In my cest file, I have the following function:
public function testUserDb(WebGuy $I)
{
$I->seeInDatabase('Users',['Email' => 'someguy#email.com']);
}
But I get the following error when running:
[Codeception\Exception\Module]
(Exception in Db) could not find driver while creating PDO connection
So I'm guessing ms sql doesn't work..
It looks like I'm not going to have any joy - anyone know if Behat has ms sql / sql server support?
Thanks
Jon.
Behat itself doesn't have anything to do with databases. If you need connecting to one from a Behat context file, you just use whatever is used in your application.
I've successfully used Doctrine with Behat for example, also with mssql.
For mssql integration you will need the doctrine-pdo-dblib package.
I'm new to Play framework. I'm trying to configure MySQL database as a datasource to be used with Play.
i have done following setting to connect mysql database to play..
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/phpmyadmin/index.php?db=formdemo&token=3882f545563c7df106e1daf21515e1b7#PMAURL:db=formdemo&server=1&target=db_structure.php&token=3882f545563c7df106e1daf21515e1b7"
but i am getting following configuration error.
play.api.Configuration$$anon$1: Configuration error[Cannot connect to
database [default]]
I am not able to connect my wamp localhost database to play.
How do I modify the configuration file to use a mysql database as opposed to an in-memory version. Do I need to setup an entirely separate DB or can I modify the db.default.url property?
I'm using Play! 2.1.
I have resolved with issue. Thank You for your guidance.
Few lines to Put.
dependency
"mysql" % "mysql-connector-java" % "5.1.18"
Conf
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/FORMDEMO?characterEncoding=UTF-8"
db.default.user=root
db.default.password=""
Follow the reference,
http://blog.knoldus.com/2013/01/28/play-framework-2-0-connectivity-with-mysql-in-scala/
Your url should be in this structure:
db.default.driver=com.mysql.jdbc.Driver
db.default.url="mysql://username:password#localhost/formdemo"
If you didn't set the default password, it is usually root with no password, like this:
db.default.url="mysql://username:#localhost/formdemo"
How do I connect to a MSSQL database using Perl's DBI module in Windows?
Use DBD::ODBC. If you just create a data source with the Control Panel -> System Management -> ODBC Data Sources -> System Data Source or User Data Source (those are the names as I remember them, but my XP isn't in English, so I can't check), then all you have to do is use the name of that data source in the DBI connect string.
my $dbh = DBI->connect("dbi:ODBC:$dsn", $user, $pwd, \%attr);
The difference between User and System data source is that the latter is usable by any user.
See also: HOW TO: Create a System Data Source Name in Windows XP
Couldn't find this anywhere reliable. Use Perl code similar to
use DBI;
my $dbs = "dbi:ODBC:DRIVER={SQL Server};SERVER={ServerName}";
my ($username, $password) = ('username', 'password');
my $dbh = DBI->connect($dbs, $username, $password);
if (defined($dbh))
{
#write code here
$dbh->disconnect;
}
else
{
print "Error connecting to database: Error $DBI::err - $DBI::errstr\n";
}
Checking Perlmonks, I see the suggestion to actually use the Sybase DBI driver for connecting to MS SQL. Which makes sense, given that MS SQL has its origins in the Sybase code. ODBC works, too, of course.
Using OLEDB with Integrated Security (Windows Authentication):
DBI:ADO:Provider=SQLOLEDB.1;Integrated Security=SSPI;Data Source=localhost;Initial Catalog=$dbName;