com.microsoft.jdbc.sqlserver.SQLServerDriver not found - sql-server

adapter.js file:
var procedure1Statement = WL.Server.createSQLStatement("select [sname] from [TestDb].[dbo].[studentinfo]");
function procedure1() {
return WL.Server.invokeSQLStatement({
preparedStatement : procedure1Statement,
parameters : []
});
}
adapter.xml file:
<dataSourceDefinition>
<driverClass>com.microsoft.sqlserver.jdbc.SQLServerDriver</driverClass>
<url>jdbc:sqlserver://localhost;databaseName=TestDb</url>
<user>user</user>
<password>pass</password>
</dataSourceDefinition>
getting error like this:
{
"errors": [
"Runtime: java.lang.ClassNotFoundException: Class com.microsoft.jdbc.sqlserver.SQLServerDriver not found in Worklight platform or project \/HelloWorld"
],

Read the error. Your error is that the driver is missing.
Make sure you have placed the jdbc driver in your-project\server\lib
Then make sure you are correctly pointing to the database in the XML file: IBM Worklight 6.1 - Failed connecting to MS SQL using SQL adapter

Related

Error when connecting android (kotlin) app to database

I get the following error when connecting to my database:
" Caused by: org.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception."
package code.with.cal.timeronservicetutorial
import kotlinx.android.synthetic.main.activity_main.*
import java.sql.DriverManager
class ConnectionHelper {
fun ConnectDB() {
val jdbcUrl = "jdbc:postgresql://HOST/USER"
// get the connection
val connection = DriverManager.getConnection(jdbcUrl, "USER", "PW")
// prints true if the connection is valid
println(connection.isValid(0))
}
}
I suspect I didn't include the dependency of right version in my gradle, but i don't know how to find which driver version i have. I added this one:
implementation 'org.postgresql:postgresql:42.2.5'

Phpstan doctrine database connection error

I'm using doctrine in a project (not symfony). In this project I also use phpstan, i installed both phpstan/phpstan-doctrine and phpstan/extension-installer.
My phpstan.neon is like this:
parameters:
level: 8
paths:
- src/
doctrine:
objectManagerLoader: tests/object-manager.php
Inside tests/object-manager.php it return the result of a call to a function that return the entity manager.
Here is the code that create the entity manager
$database_url = $_ENV['DATABASE_URL'];
$isDevMode = $this->isDevMode();
$proxyDir = null;
$cache = null;
$useSimpleAnnotationReader = false;
$config = Setup::createAnnotationMetadataConfiguration(
[$this->getProjectDirectory() . '/src'],
$isDevMode,
$proxyDir,
$cache,
$useSimpleAnnotationReader
);
// database configuration parameters
$conn = [
'url' => $database_url,
];
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
When i run vendor/bin/phpstan analyze i get this error:
Internal error: An exception occurred in the driver: SQLSTATE[08006] [7] could not translate host name "postgres_db" to address: nodename nor servname provided, or not known
This appear because i'm using docker and my database url is postgres://user:password#postgres_db/database postgres_db is the name of my database container so the hostname is known inside the docker container.
When i run phpstan inside the container i do not have the error.
So is there a way to run phpstan outside docker ? Because i'm pretty sure that when i'll push my code the github workflow will fail because of this
Do phpstan need to try to reach the database ?
I opened an issue on the github of phpstan-doctrine and i had an answer by #jlherren that explained :
The problem is that Doctrine needs to know what version of the DB server it is working with in order to instantiate the correct AbstractPlatform implementation, of which there are several available for the same DB vendor (e.g. PostgreSQL94Platform or PostgreSQL100Platform for postgres, and similarly for other DB drivers). To auto-detect this information, it will simply connect to the DB and query the version.
I just changed my database url from:
DATABASE_URL=postgres://user:password#database_ip/database
To:
DATABASE_URL=postgres://user:password#database_ip/database?serverVersion=14.2

SQL Server connection string in Appsettings.json + .net Core 3.1

I'm trying to setup and connect to my remote development SQL Server (SQL 2017) in appsettings.json within .NET Core 3.1, I have tried the following approaches yet without any success.
"ConnectionStrings": {
//"DefaultConnection1": "DATA SOURCE=[servername];UID=[username];PWD=[password];DATABASE=[databasename]",
//"DefaultConnection2": "Data Source=[servername]; Initial Catalog=[databasename];User ID=[username];Password=[password]",
//"DefaultConnection3": "DataSource=[servername];Initial Catalog=[databasename];User Id=[username];password=[password]",
"DefaultConnection4": "Server=[servername];Database=[databasename];User Id=[username];password=[password];Trusted_Connection=False;MultipleActiveResultSets=true;"
},
Error of DefaultConnection1:
ArgumentException: Keyword not supported: 'uid'.
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string
keyword))
Error of DefaultConnection2:
ArgumentException: Keyword not supported: 'initial catalog'.
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string
keyword)
Error of DefaultConnection3:
ArgumentException: Keyword not supported: 'initial catalog'.
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string
keyword)
Error of DefaultConnection4:
ArgumentException: Keyword not supported: 'server'.
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string
keyword)
Any ideas, pointers or help is much appreciated.
thanks for your help and advice, i might have just found the solution and am able to connection the SQL database successfully now, the problem was as following:
The following package was installed on the solution:
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder
in Startup.cs the following line was used in the ConfigureServices(IServiceCollection services):
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlLite(Configuration.GetConnectionString("DefaultConnection")));
However after research i found out that i should rather use the following line:
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
Which was not accessible due the following package missing:
Microsoft.EntityFrameworkCore.SqlServer
After installing this package via package Manager using the following command:
Install-Package Microsoft.EntityFrameworkCore.SqlServer
I was able to access the SQL server using the following connection string:
"ConnectionStrings": {
"DefaultConnection": "Server=[servername];Database=[databasename];Persist Security Info=True;User ID=[username];Password=[password];MultipleActiveResultSets=True;"
},
For safety, as Christian pointed out, I removed also the other connectionstring references.
Probably it's just because you're not supposed to put comments (//) in JSON as JSON is a data format and doesn't support comments. So try actually removing the lines starting with // from your config.
Your setup in appsettings.json is fine.
Suppose the model in your cs file is mytestModel.
Here is the code to read the connection string:
public class mytestModel : PageModel
{
public string connectstring = "";
private IConfiguration MyConfiguration;
public mytestModel (IConfiguration _configuration)
{
MyConfiguration = _configuration;
}
public void OnGet()
{
connectstring = this.MyConfiguration.GetConnectionString("DefaultConnection4");
}
}
It should be noted that the type of model (eg. PageModel) does not matter. The name of the model is what matters.

Etherpad - PostgreSQL error: language "plpgsql" does not exist

I installed Etherpad lite and tried to use it with PostgreSQL database, but got this error:
events.js:72
throw er; // Unhandled 'error' event
^
error: language "plpgsql" does not exist
at Connection.parseE (/opt/openerp/etherpad/etherpad-lite/src/node_modules/$
at Connection.parseMessage (/opt/openerp/etherpad/etherpad-lite/src/node_mo$
at Socket.<anonymous> (/opt/openerp/etherpad/etherpad-lite/src/node_modules$
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
RESTART!
In other servers I didn't have such problem using PostgreSQL with Etherpad.
I created database using this command:
crate database etherpad WITH TEMPLATE template0;
My configuration in etherpad is like this:
"dbType" : "postgres",
"dbSettings" : {
"user" : "db_user",
"host" : "localhost",
"password": "my_password",
"database": "etherpad"
},
Everything else is left unchanged, except I commented dirty db settings.
P.S. with dirty db it works.
If you are using 9.1 and below, you should CREATE LANGUAGE plpgsql in template1, and then create your database based on that template. This should not happen or be required on PostgreSQL 9.2 and above.

How to use MSSQL DSN as URL in DataSource.groovy

I have been trying this code in DataSource.groovy but its showing an error of "No suitable driver"
dataSource
{
pooled = true
driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
String url="jdbc:microsoft:sqlserver:DSNname";
}
I have already included two jdbc SQLserver drivers sqljdbc, sqljdbc4 (*.jar files).
I also tried this code but went futile.
DataSource
{
driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
//url="jdbc:sqlserver://localhost:1433;database=DBNAME" its working
url="jdbc:odbc:myDSN"
username="sa"
password=""
}
Thanks a ton in advance.

Resources