How can I connect Grails 4 with SQL Server database? - sql-server

I followed the normal procedure for connecting with database as it's done in SPRING BOOT but none of my method seems to work. Also I used the below procedure for connects SQL Server and I added SQL Server driver in lib directory but there is no any result. Is there any one who can help me with this please?
dataSource:
pooled: true
jmxExport: true
driverClassName: net.sourceforge.jtds.jdbc.Driver
username: cctz
password: 'cctz*2020'
dialect: org.hibernate.dialect.SQLServer2019Dialect
environments:
development:
dataSource:
dbCreate: update
url: jdbc:jtds:sqlserver://<192.168.200.136>\SQLEXPRESS:1433;databaseName=deptech_db;user=cctz;password=cctz*2020;
test:
dataSource:
dbCreate: update
url: jdbc:jtds:sqlserver://192.168.200.136:1433;DatabaseName=deptech_db
production:
dataSource:
dbCreate: update
url: jdbc:jtds:sqlserver://192.168.200.136:1433;DatabaseName=deptech_db
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

Related

JDBC restful SQL request for TDengine

My springboot project has correctly configured JDBC of TDengine:
datasource:
dynamic:
druid:
max-active: 20
initial-size: 4
min-idle: 4
max-wait: 60000
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
test-while-idle: false
test-on-borrow: false
test-on-return: false
filters: stat
primary: td-engine
strict: false
datasource:
td-engine:
driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
url: jdbc:TAOS-RS://192.168.1.161:6041/taoskeeper?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
username: ****
password: ****
When I execute on a existed table: table1:
select * from table1
{\"status\":\"error\",\"code\":535,\"desc\":\"Database not specified or available\"}
I got the result of not specified or available error, even I execute "use mydatabase" first.
The JDBC restful api is stateless, which means database has to be selected in sql, the correct sql statement should be :
select * from mydatabase.table1

Django 2.0.9 using dockerized MS Sql Server on Mac, varbinary conversion error

I am assuming this is NOT a common scenario -- however I am running Django 2.0.9, pyodbc 4.0.24, django-pyodbc-azure 2.0.4.1 and ODBC 17 on my Mac, talking to SQL Server running in Docker, Microsoft SQL Server 2017.
For reasons also beyond my control, I am modeling a system where uploads are stored a BLOBs, varbinary types in SQL Server parlance.
No matter what I do, as soon as I declare a BLOB type and attempt to load a fixture (without a BLOB) I get the error:
Could not load mytype.MyType(pk=3455): ('22018', '[22018] [FreeTDS][SQL Server]Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query. (257) (SQLExecDirectW)')
The model is as follows:
class MyType(models.Model):
id = models.BigAutoField(primary_key=True)
desc = models.CharField(
max_length=4000, blank=True, null=True)
name = models.CharField(max_length=8, blank=True, null=True)
blah_id = models.BigIntegerField(blank=True, null=True)
related_thing = models.ForeignKey(
Thing,
on_delete=models.PROTECT,
blank=True,
null=True)
... etc ...
pdf = models.BinaryField(blank=True, null=True) # here is the sticking point
class Meta:
# etc
I loaddata using a fixture with everything BUT the syllabus and I always get there error:
Problem installing fixture '/path/to/fixtures/0011_mydata.json': Could not load mytype.MyType(pk=3455): ('22018', '[22018] [FreeTDS][SQL Server]Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query. (257) (SQLExecDirectW)')
I believe the error is a red herring, the real problem lies in a driver specific to Mac <-> Sql Server in Docker
Any help is appreciated!
The problem, in this case is the connection string:
DATABASES = {
# Microsoft SQL Server version
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'foo',
'USER': 'blah',
'PASSWORD': 'password',
'HOST': '0.0.0.0',
'PORT': '1433',
'OPTIONS': {
'driver': 'FreeTDS',
},
},
}
Should be
DATABASES = {
# Microsoft SQL Server version
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'foo',
'USER': 'bar',
'PASSWORD': 'password',
'HOST': '0.0.0.0',
'PORT': '1433',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
},
},
}
FreeTDS was the problem. I do not know why, but eliminating it from the chain fixed the problem.

Spring boot JPA ddl-auto update

When i try to set ddl auto to update, every time I run the application, it shows that hibernate tries to create the tables again. I am trying to add another column in the database using the entity
#Column(name = "xref_reason", length = 20)
private String xRefReason;
Shouldn't it creates this column only that I added?
Here is the error.
Hibernate: create table tbcodetable (id bigint identity not null, codename varchar(255), codevalue varchar(255), desc1 varchar(255), desc2 varchar(255), primary key (id))2018-06-26 16:23:09.342 WARN 4284 --- [ost-startStop-1] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: There is already an object named 'tbcodetable' in the database.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:258) ~[mssql-jdbc-6.2.2.jre8.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1535) ~[mssql-jdbc-6.2.2.jre8.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:845) ~[mssql-jdbc-6.2.2.jre8.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:752) ~[mssql-jdbc-6.2.2.jre8.jar:na]
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7151) ~[mssql-jdbc-6.2.2.jre8.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2478) ~[mssql-jdbc-6.2.2.jre8.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:219) ~[mssql-jdbc-6.2.2.jre8.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:199) ~[mssql-jdbc-6.2.2.jre8.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(SQLServerStatement.java:729) ~[mssql-jdbc-6.2.2.jre8.jar:na]
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-2.7.8.jar:na]
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-2.7.8.jar:na]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
... 119 common frames omitted
even the foreign keys has the same error.
application.yml
spring:
profiles:
active: dev
datasource:
url: jdbc:sqlserver://localhost;database=dbname
username: user
password: password
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
hikari:
minimum-idle: 1
maximum-pool-size: 10
pool-name: collectionPool
auto-commit: false
jpa:
show-sql: true
hibernate:
default_schema: dbo
ddl-auto: update
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy

Apache Drill - SQL Server plugin does not 'Show Tables'

Using Apache Drill,
I successfully created new plugin : mssql
Configuration:
{
type: "jdbc",
driver: "com.microsoft.sqlserver.jdbc.SQLServerDriver",
url: "jdbc:sqlserver://99.99.99.999:1433;databaseName=ABC",
username: "abcuser",
password: "abcuser",
enabled: true
}
But when i try to query again a table I get an error:
select * from mssql.ABC.dbo.TableName
Error:
org.apache.drill.common.exceptions.UserRemoteException: VALIDATION ERROR: From line 1, column 15 to line 1, column 19: Table 'mssql.ABC.dbo.TableName' not found SQL Query null [Error Id: feba9fdb-1621-438a-9d7c-304e4252a41f on AA99-9AA9A99.xyz.abc.com:31010]
Even the below command returns no tables:
show tables;
It should be like
select * from mssql.dbo.TableName

Django SQL Server Error: "Cannot create new connection because in manual or distributed transaction mode."

I have some strange issue with querying SQL Server from django.
When I query db twice in single request, I got errors in some cases. Namely when first db query returns big amount of data, we end up with error while querying db second time.
Details:
We're using Microsoft SQL Server backend for Django (https://bitbucket.org/Manfre/django-mssql/src) running on windows.
We want allow user to filter data from some table ("Activity") via form, display it on the website's table and then show related data from another table ("Frames") on map.
class Frames(models.Model):
...
class Activity(models.Model):
frame_from = models.ForeignKey(Frames, ...)
...
The problem is: when we want to filter larger amount of data from Activity (let's say 200rows x 6 colums), we can not make other queries in the same request on table Frames (MARS is turned on in Django settings.py):
result = Aktywnosci.objects.filter(qset1)
is always ok, but
path = Frames.objects.filter(qset2)
when the previous query returned larger amount of data, raises OLE DB Error:
'Microsoft OLE DB Provider for SQL Server' Error: Cannot
create new connection because in manual or distributed transaction mode.
PS. Database settings from settings.py:
# Database for this installation.
DATABASES = {
'default':{
'ENGINE': 'django.db.backends.sqlserver_ado',
'NAME': '***',
'USER': '***',
'PASSWORD': '***',
'HOST': '***',
'PORT': '',
'OPTIONS' : {
'provider': 'SQLOLEDB',
'use_mars': True,
}
}
}
PS2. I came across this issue on the google-code page of djang-mssql: http://code.google.com/p/django-mssql/issues/detail?id=79 - but it seems to be solved in new version of package...
What can I do about it?
Thanks in advance
We got the solution at bitbucket: https://bitbucket.org/Manfre/django-mssql/issue/13/ole-db-provider-for-sql-server-error from Michael Manfre - thanks a lot for this.
The solution is following:
"SQLOLEDB and MARS doesn't work very well and I intend on changing all of the documentation and defaults to assume a native client driver will be used. Try using the native client; "SQLNCLI10" or "SQLNCLI11".
DATABASES = {
'default': {
'ENGINE': 'sqlserver_ado',
'NAME': 'mydb',
'HOST': r'localhost',
'USER': '',
'PASSWORD': '',
'OPTIONS': {
'provider': 'SQLNCLI10',
'extra_params': 'DataTypeCompatibility=80;MARS Connection=True;',
},
}
}
Is "use_mars=True" set up in your "settings.py" file?
http://django-mssql.readthedocs.org/en/latest/settings.html
If this doesn't work, I have a question: is your selection in SQL Server involving tables with triggers on them (transact SQL scripts) - in this case the SQL Server will use a static cursor instead of a firehose one (which is what you need) therefore you will get your error. Try to get rid of the triggers, use some views in SQL Server and select from them instead of tables.

Resources