EF7: error connecting to a local db database - entity-framework

I'm trying to create a new asp.net core app which uses EF7 to access a local db database and I'm having some problems with the connection string. I've installed the local db service and I have already created several instances:
PS C:\Users\luisabreu> sqllocaldb info
MSSQLLocalDB
ProjectsV12
ProjectsV13
v11.0
MSSQLLocalDB is running v12:
PS C:\Users\luisabreu> sqllocaldb info mssqllocaldb
Name: MSSQLLocalDB
Version: 12.0.2000.8
Shared name:
Owner: GRM\luisabreu
Auto-create: Yes
State: Running
Last start time: 05/04/2016 08:46:17
Instance pipe name: np:\\.\pipe\LOCALDB#518FD662\tsql\query
This is the connection string I'm passing to EF:
{
"usersCnnString": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=UsersInfo;Integrated Security=True"
}
Btw, I've already tried this one too:
"usersCnnString": "Server=(localdb)\\mssqllocaldb;Database=UsersInfo;Trusted_Connection=True"
And here's the setup code I'm using for setting up ED dependencies:
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<UsersContext>(options => options.UseSqlServer(Configuration["usersCnnString"]));
Whenever I try to access the database,I end up with the following error:
System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Specified LocalDB instance name is invalid.)
I'm surely doing something wrong, but what?
thanks!
Luis

Well, it was something simpler...don't forget to kill iis express whenever you change the config of an ASP.NET Core app so that you'll get the correct config data when you re-run the app. The problem was that when I pasted the path:
Server=(localdb)\\mssqllocaldb...
into the json file, VS 2015 automatically escaped the string, turning it into:
Server=(localdb)\\\\mssqllocaldb...
Yes, I've noticed it, but only after trying to load the app on the browser. I corrected the path but didn't kill the IIS Express instance I was using to test my app. So, the error message was absolutely correct because it was still using the old path (which was trying to reach the mssqllocaldb instance running on a localdb server).
Again, stupid error. Hoping that my mistake will save someone else's 30 mins in the future...

if I create a project with user accounts using VS 2015 with RC1 the project template generates the connection string like this:
{
"Server=(localdb)\\mssqllocaldb;Database=thedbnamehere;Trusted_Connection=True;MultipleActiveResultSets=true"
}
I would try making it closer to that, but also wondering if for some reason UsersInfo might not be a valid name, could be some keyword clash
I noticed that vs uses the "userSecretsId" from project.json as the dbname, not sure if that is required but might be worth trying

Related

Is there a way to use Flyway on AS400?

I need to implement migration tool like Flyway in order to use Jenkins to deploy DB changes.
I tried to add jt400.jar file and added configuration as follows:
flyway.url=jdbc:as400://192.168.171.251:446/DBDEV
flyway.driver=com.ibm.as400.access.AS400JDBCDriver
as a driver and it would not connect with this message:
ERROR: No database found to handle jdbc:as400://192.168.171.251:446/DBDEV
I also tried with using IBM DB2 driver and had configuration
flyway.url=jdbc:db2://192.168.171.251:50000/DBDEV
flyway.driver=com.ibm.db2.jcc.DB2Driver
this time I am getting this kind of refusal message
ERROR:
Unable to obtain connection from database (jdbc:db2://192.168.171.251:50000/DBDEV) for user 'DEVUSER':
[jcc][t4][2043][11550][4.26.14] Exception java.net.ConnectException: Error opening socket to server
/192.168.171.251 on port 50,000 with message: Connection refused (Connection refused).
ERRORCODE=-4499, SQLSTATE=08001
With this test migration I am trying to create a simple table by executing this sql
CREATE TABLE PERSON (
ID INT NOT NULL,
NAME VARCHAR(100) NOT NULL
);
Anyone had this situation and solved it?
I believe that at present there is no support for flyway to work with IBM i (as/400) regardless of whether you use jt400.jar or an IBM jdbc driver.
You can either use a different database-schema versioning tool, or find a fork of flyway that supports i-series (or pay someone to create and support such a fork, it is open source...).
It seems that currently (flyway 7.7.2) does not recognize a URL that starts with "jdbc:as400:" as a Db2 URL, so it throws an exception, which is the reason that the jt400.jar style URL is rejected with exception:
"No database found to handle ..."
The github history tells a story (see: https://github.com/flyway/flyway/issues/105).
Looks like the devs did not succeed to get the AS400 support added due to the lack of a suitable available i-series testing/dev environment (and also available to travis ci) . There may have been at least one PR for such support in the past, although it seems to be removed.
If you try to use the IBM db2jcc4.jar driver to connect to i-series (as400) with a url similar to: jdbc:db2://hostname/dbname, and you explicitly use an IBM jre , and have the relevant license file (e.g. db2jcc_license_cisuz.jar on the CLASSPATH), then flyway will connect and then report the exception similar to:
Unsupported Database: AS 7.4
The flyway source code shows that flyway does not recognize this database product-name and version, at current flyway version 7.7.2.
Are you sure DBDEV is the name of your Db2 data base on the IBM i?
Use the Work with RDB Directory Entry (WRKRDBDIRE) from the green screen, and look for the *LOCAL entry.
Or use the Access Client Solutions (ACS) "Schemas" tool to see a list of DB on your system.
The above shows 2 DB's, UT29p63 and Dbtest

Getting org.postgresql.util.PSQLException: FATAL: database "null" does not exist in SpringCloudDataFlow

I'm getting "org.postgresql.util.PSQLException: FATAL: database “null” does not exist" in connecting PostgreSQL to my SpringCloudDataFlow Server App in PCF environment.
I have successfully performed following steps.
Deployed SCDF(Spring-Cloud-Dataflow) server in PCF (1.7.3 version)
Created PostgreSQL service instance with 'Standalone' plan. Note: I don't have any other database service available in PCF marketplace.
Connect to that instance (using host (IP) and autogenerated credentials) by a third party software and create database using script 'CREATE DATABASE scdf'
Bind 'PostgreSQL service instance' with 'SCDF server app'.
Set environment variables
spring_datasource_driver_class_name = org.postgresql.Driver
spring_datasource_username [PostgreSQL_Instance_Autogenerated_Username]
spring_datasource_password [PostgreSQL_Instance_Autogenerated_Password]
spring_datasource_url "jdbc:postgresql://10.254.48.231:5432/scdf"
After setting environment variables, when I restart SCDF server app, it gives exception and crash the app
org.postgresql.util.PSQLException: FATAL: database “null” does not exist
Can anyone help please.
A good first step is to make sure the PostgreSQL service-instance is functional on PCF.
Perhaps you could connect to the host/user/pass from outside of PCF via a DB client tool or from other applications. If this is successful standalone, then there's something wrong in supplying the credentials to the SCDF-server.
It is unclear how you're supplying database properties to SCDF. You may have to wrap those "datasource" properties as a well-defined JSON, and provided as the value for SPRING_APPLICATION_JSON property attached to the SCDF-server. If you continue to see issues, please update the description with manifest.yml and other information about the environment.

Postgresql and ssl start up error

I am new to freenode and postgresql. I am trying to migrate from mysql to postgresql. Currently trying to set up server for ssl. Have created my server certs and configured the .conf files for ssl according to the manual as far as I can see. Trying to restart postgre sql service fails. Windows event log gives me an event ID of 0 and says
pg_ctrl could not start server examine the log output.
I can't find any log detailing the failure to start in the postgresql folders.
I have tried to register the pgevent.dll as advised by the postgresql manual (18.11 of most recent version), but I get an error message
The module "C:postgreSQL\pg10\lib\postgresql\pgevent.dll" was loaded but the entry-point DllRegisterServer was not found
I believe that means it is either not a registrable dll or it's corrupt.
Can anyone please advise how I can track on Windows the error that is causing Postgre to fail to start?

Can't connect to SQL Azure from EF, but can from SSMS

We have an Azure SQL server running which we use for our Azure Web App. The Web App can connect without a problem. We're trying to remotely update the database with the latest EF migrations via a C# console application.
However we get the following exception.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
We tried connecting from the same PC with SSMS and we got in without any problems. And yes, before anyone asks we whitelisted the IP in Azure, else we wouldn't even had access via SSMS. We also tried with and without "tcp:" in the connectionstring.
This is the connectionstring we use in the Web and Console Application:
Server=tcp:{servername}.database.windows.net;Database={dbname};user id = {userid};password = {password};MultipleActiveResultSets=True;
In SSMS we just use {servername}.database.windows.net and use the credentials.
Thanks in advance.
We haven't been able to solve this issue. We instead chose to go with ReadyRoll, which suits us fine.
Azure SQL requires secured connection. You have to add the following to your connection string:
Trusted_Connection=False;Encrypt=True;

OrientDB 2.2.13 console.sh: getting "Cannot create a connection to remote server address(es)"

I have an embedded database where I start an OServer and trying to connect to it from the console. I've been doing this successfully for many months and upgrading the database as new versions come out. Now, with 2.2.13, the embedded operations seem to work but I can't connect to the server with the 2.2.13 console.sh. I get the message:
Error: com.orientechnologies.orient.core.exception.OStorageException: Cannot create a connection to remote server address(es): [127.0.0.1:2424]
DB name="master"
The java code running the embedded database gets the following exception:
$ANSI{green {db=db}} Error executing request
com.orientechnologies.orient.core.exception.ODatabaseException: Error on plugin lookup: the server did not start correctly
DB name="db"
at com.orientechnologies.orient.server.OServer.getPlugin(OServer.java:850)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.openDatabase(ONetworkProtocolBinary.java:857)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.handshakeRequest(ONetworkProtocolBinary.java:229)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.execute(ONetworkProtocolBinary.java:194)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:77)
Seems to be looking for the 'cluster' plugin.
Any idea why this doesn't work anymore? It did work in 2.2.12.
Thanks
Curtis
Seems I had automatic backup turned on but the config file was missing. So, the server looked like it started up but actually didn't.
I created the config file and set enabled to false. Still didn't start up because it sees the false and stops the configuration and throws an exception because the 'delay' parameter isn't set.
I think orientdb should start up without backups enabled if the config file is missing or the enabled parameter is set to false.
At least the console is working now.