I am trying to access and read data from a .mdf Microsoft SQL Server file (located on a remote server) inside a Java application running locally.
I have a SQL Server JDBC driver installed and it's on my classpath but I still cannot seem to access the file, I get the following error:
The connection to the host PD-SQLTEST, named instance sqlexpress failed.
Error: "java.net.SocketTimeoutException: Receive timed out"
I am defining the connection URL as follows:
String URLSqlServer ="jdbc:sqlserver://PD-SQLTEST\\SQLEXPRESS; databaseName=AOMLive";
The .mdf is called AOMLive.mdf
Any ideas what I am doing wrong here? Does the SQL Server Database on the remote server have to be running for me to access?
You must have the SQL Server running; JDBC cannot read that file directly.
Related
I am trying to migrate some code from JavaFX to use C# for Windows Forms. In Java, I was using JDBC and could connect just fine programmatically. Nos that I am trying to use C# I am getting this error:
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server).
I am using the same server address and credentials. I'm using System.Data.SqlClient. I've tried a bunch of different combinations but can't get the connection string to work.
String connectionString = "server=[Server URL];database=[Database Name];persist security info=true;user id=[Username];pwd=[Password]";
Here is an example of the mysql connection string:
string connectionString = "datasource= <database ip or domain>; port=<port, usually 3306>;username=<database user>;password=<user's password>;SslMode=none<this is important if you don't use ssl>;database=<your database>";
I think the reason you can't connect is because you haven't specified the SslMode.
I have installed SQL Server 2014 in Windows 10 with database port (1433) instead of a named instance with Java8. I am trying to use the below mentioned connection string format to connect.
jdbc:sqlserver://localhost:1433;databaseName=TEST_DATABASE;userName=user;password=user
But the connection fails. The SQL JDBC driver I am using is sqljdbc42.jar. I am able to connect successfully while trying to SQL server created using instance name instead of port. The format mentioned below works fine.
jdbc:sqlserver://localhost;instanceName=COMP_SYS;databaseName=NEW_DATABASE;userName=user;password=user
Only with DB port connection is getting failed. What am I missing.
I did a java project with netbeans using derby. The project runs fine in the IDE, but when i build it and run from the .jar file without starting server from the netbeans, it displays:
"java.net.ConnectException : Error connecting to server localhost on port 1527
with message Connection refused: connect."
How can i connect to the database on my client`s machine without netbeans on it?
You need to know the IP of your DB server, as localhost or 127.0.0.1 refers to the DB installed on local machine, and if you run the app on client's machine it is pretty sure, that this DB is not there locally. You need to specify the exact IP address, if multiple clients should connect to the same DB.
If you just need a DB per app, then you can use Embedded Derby, that starts and stops with your application, so you don't really need external server (very good solution in case when this is the only app that use this DB):
public String driver = "org.apache.derby.jdbc.EmbeddedDriver";
...
Class.forName(driver).newInstance();
Get an Embedded Connection
public String protocol = "jdbc:derby:";
...
conn = DriverManager.getConnection(protocol + "derbyDB;create=true", props);
That embedded connection URL, fully constructed, looks like this:
jdbc:derby:derbyDB;create=true
I'm unable to connect to db2 server using db2cmd command
db2 connect to mydb user myuser using password
Getting the following message
SQL8002N An attempt to connect to a host failed due to a missing DB2 Connect product or invalid license. SQLSTATE=42968
But I have successfully connected to this database using jdbc and I can view the structure.
Has anybody experienced such issue?
Are you trying to connect to a iSeries o z/390? or just a LUW (Linux, Unix Windows?)
If you are trying to connect to one of the two first, you need a DB2 Connect license, because they use the DRDA architecture, and it uses a special license.
Check the license
db2licm -a
If you are trying to connect to a LUW, you do not need any DB2 connect license, but probably there is a problem in you cataloged databases. Check the
db2 list node diretory
db2 list db directory
Is the database a remote server or is it a local connection?
Also, try to attach to the remote instance, in order to check that the node catalog is right
db2 attach to remoteInstance
As the error message says, you need DB2 Connect to serve as a gateway for CLI connections. The JDBC driver does not need the gateway, as it implements the required protocol.
I've tryed to create a connection with a Microsoft SQl Server 2008 database through JDBC on Eclipse SDK. I've dowloaded JDBC driver from microsoft and I've installed it, then I've added at my System environment variables CLASSPATH the path of sqljdbc4.jar file. After icluding in the Eclipse project the jar file I've tryed to create the connection using:
String connectionUrl = "jdbc:sqlserver://localhost;integratedSecurity=true";
Connection con = DriverManager.getConnection(connectionUrl);
but it doesn't works, and launch me this exception:
com.microsoft.sqlserver.jdbc.SQLServerException: TCP/IP connection
at host localhost, port 1433 failed. Error: "Connection refused:
connect. Verify connection properties and make sure an instance of SQL
Server is running on the host and is accepting TCP/IP connections at
the port. Be sure no firewall blocks connections at the port.
I'm working on a JRE 1.6 so a sqljdbc4 should work, and I've created a working ODBC, so the server is responding, and the error should be in java command or JDBC installation.
Can anyone help me?
At the risk of stating the obvious, this looks to me as if TCP connections haven't been enabled on SQL Server. You have to manually enable them, they don't come enabled by default.
There's an article on MSDN here which explains how to enable TCP protocols for SQL 2005/2008.
Following are the quick trouble shooters:
Try to connect to your server using external front end.
Check if your firewall blocks the connection to the port
Check to see if server is really up.
A Suggestion :
If you are using eclipse , you don't need to add the jar into CLASSPATH variable , you can just add it in library of your project to make it available at runtime