SQL Express connection string: mdf file location relative to application location

Thanks everyone, I used a combination of your responses. In my app.config file my connection string is defined as follows <add name=”MyConnectionString” connectionString=”Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Database=MyDatabaseForTesting;Trusted_Connection=Yes;” /> In my unit test class I set the DataDirectory property using the following [TestInitialize] public void TestInitialize() { AppDomain.CurrentDomain.SetData(“DataDirectory”, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, “Databases”)); // rest of initialize implementation … }

PG::ConnectionBad – could not connect to server: Connection refused

It could be as simple as a stale PID file. It could be failing silently because your computer didn’t complete the shutdown process completely which means postgres didn’t delete the PID (process id) file. The PID file is used by postgres to make sure only one instance of the server is running at a time. … Read more

How does spring.jpa.hibernate.ddl-auto property exactly work in Spring?

For the record, the spring.jpa.hibernate.ddl-auto property is Spring Data JPA specific and is their way to specify a value that will eventually be passed to Hibernate under the property it knows, hibernate.hbm2ddl.auto. The values create, create-drop, validate, and update basically influence how the schema tool management will manipulate the database schema at startup. For example, … Read more

Closing database connections in Java

When you are done with using your Connection, you need to explicitly close it by calling its close() method in order to release any other database resources (cursors, handles, etc.) the connection may be holding on to. Actually, the safe pattern in Java is to close your ResultSet, Statement, and Connection (in that order) in … Read more

MySQL Error: : ‘Access denied for user ‘root’@’localhost’

All solutions I found were much more complex than necessary and none worked for me. Here is the solution that solved my problem. There isn’t any need to restart mysqld or start it with special privileges. sudo mysql — for MySQL ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘root’; — for MariaDB ALTER USER ‘root’@’localhost’ … Read more

How do I manage MongoDB connections in a Node.js web application?

The primary committer to node-mongodb-native says: You open do MongoClient.connect once when your app boots up and reuse the db object. It’s not a singleton connection pool each .connect creates a new connection pool. So, to answer your question directly, reuse the db object that results from MongoClient.connect(). This gives you pooling, and will provide … Read more

How to connect to SQL Server database from JavaScript in the browser?

You shouldn´t use client javascript to access databases for several reasons (bad practice, security issues, etc) but if you really want to do this, here is an example: var connection = new ActiveXObject(“ADODB.Connection”) ; var connectionstring=”Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB”; connection.Open(connectionstring); var rs = new ActiveXObject(“ADODB.Recordset”); rs.Open(“SELECT * FROM table”, connection); rs.MoveFirst while(!rs.eof) { document.write(rs.fields(1)); rs.movenext; … Read more

ExecuteReader requires an open and available Connection. The connection’s current state is Connecting

Sorry for only commenting in the first place, but i’m posting almost every day a similar comment since many people think that it would be smart to encapsulate ADO.NET functionality into a DB-Class(me too 10 years ago). Mostly they decide to use static/shared objects since it seems to be faster than to create a new … Read more