MS SQL Server named instance connection using Spring JDBC Template - sql-server-2005

All,
I am trying to connect SQL Server named instance using Microsoft JDBC Driver as well as jTds.
Both were giving different problems .
Microsoft Driver issue :
Connection URL :
dataSource.setUrl("jdbc:sqlserver://xx.xx.xx.xx;databaseName=DBNAME;instanceName=SQL2005");
instance SQL2005 has failed. Error: java.net.SocketTimeoutException: Receive timed out. Verify the server and instance names, check that no firewall is blocking UDP traffic to port 1434, and for SQL Server 2005 or later verify that the SQL Server Browser Service is running on the host.
jTDS:
Connection url :
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("net.sourceforge.jtds.jdbc.Driver");
dataSource.setUrl("jdbc:jtds:sqlserver://XX.XX.XX.XX:1434/DB_NAME;namedPipe=true;domain=dom");
pipe\sql\query (Logon failure: unknown user name or bad password)
Please give me a good solution to connect MS SQL SERVER NAMED INSTANCES using spring.
Thanks in advance

Based on the error message, and the fact that it is missing from your code, you need to set user name and password somewhere too.
dataSource.setUser("db_username_here");
dataSource.setPassword("db_password_here");

Related

Can't connect to a SQL server remotely

i'm a new to stackoverflow but maybe i may also ask a question. I also hope i can help others to find solutions regarding their issues.
So, here we go. I moved a database from an old SQL server to a new one. While trying to configure the application to use the new location of that database shows up an error message like this:
Cannot connect to \MSSQLSERVER.
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: 25 - Connection string is not valid) (Microsoft SQL Server, Error: 87)
The parameter is incorrect
So i started an analysis to solve this issue. And i checked those things:
DNS resolution -> check
ping to the new SQL Server -> check
Firewall disabled -> check
Remote connections on SQL Server enabled -> check
Still receiving this error message. I configured the SSMS on the application server and ran that as SQL server service user without any success.
SQL Server browser is running
TCP/IP is enabled using the default port 1433
I am not sure regarding the SQL server instance name. IMHO it is shown in the service name and the default instance name is MSSQLSERVER. The error message mentions that the connection string is not valid.
So, at this point i don't have any further ideas.
Greetings,
Chris
[EDIT] I don't use any specific connection string because i connect using SSMS.
enter image description here
[EDIT2]
I was able to connect locally using the hostname (not localhost).
All tests below do not use an instance name
Test Result
-----------------------------------------------------
Locally, hostname, AD Auth Success
Remote, hostname, AD Auth The target principal name is incorrect. Cannot generate SSPI context
Remote, FQDN, SQL Auth Connection string is not valid
Step 1: Login Authentication Windows or SQL Server
Check your login Authentication whether its Windows or SQL Server.
Step 2: Use (.) (dot) instead of complete server name
If you are using local MS sql database then you can use (.) (dot) instead of complete server name.
Step 3: Enter Correct Host Name
Enter your correct host name: (hostname\SQLEXPRESS) my_hostname\SQLEXPRESS (in case of SQL Server Express) or (my_hostname\mssqlserver).
Step 4: Try localhost slash () then host name
You can also try localhost slash () then host name, here is sample as (localhost\SQLEXPRESS) or (localhost\mssqlserver).

Jmeter can't connect to local ms sql server

I need to connect Jmeter to my local MS SQL Server database. Everything works fine, when I'm working with remote databases, but when it comes to local databeses I get stuck at the beginning.
I've tried these settings to connect to my DB:
Database URL: jdbc:sqlserver://DESKTOP-IEK3G1S\SQLEXPRESS;DatabaseName=TestBase
JDBC Driver class : com.mircrosoft.sqlserver.jdbc.SQLServerDriver
And this is what i get:
Response message: java.sql.SQLException:
Cannot create PoolableConnectionFactory (The connection to the host DESKTOP-IEK3G1S, named instance sqlexpress has failed.
Error: "java.net.SocketTimeoutException:
Receive timed out". Verify the server and instance names, check that no firewall is blocking UDP traffic to port 1434, and for SQL Server 2005 or later verify that the SQL Server Browser Service is running on the host.)```
Well, I had to recreate my SQL Browser connection and manually shutdown everything that was turned on in my Firewall options and everything has started working.
Enable TCP/IP in the SQL server configuration:
Enable IP address and set the desired TCP port for the connection:
SQL Server default TCP port is 1433, most probably you should be using 1433 in your JDBC Connection Configuration setup
Enable SQL Server Authentication mode or add Integrated Security = true to your JDBC URL if you plan to connect with your current credentials (you will need to have sqljdbc_auth.dll file under Java Library Path)
Make sure to use matching SQL Server JDBC Driver
Change "Validation Query" to be select 1

Connect ot SQL Server Express 2012 over the internet

I've been trying to configure my sql server express 2012 to recieve connections over the internet without any luck for hours (I'm using Team Foundation Service for nightly builds but it fails when it tries to run unit tests that interact with the sql server).
All I keep getting is this message :
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 have tried the following in order to solve this:
Install and run SQL Server Browser
Enable TCP/IP for the sql server instance (using the default SQLEXPRESS)
Enable Port forwarding in my router
Added SQL Server and SQL Server browser apps to the firewall allowed apps list.
Banged my head against the wall.
My sql server is mixed mode, and the username and password are correct (it works when using the local ip address)
I've read every post here regarding this problem but nothing so far..
I'm pretty desperate so any advice will be greatly appreciated!
thanks
Solved it.
Only had to enter my public IP adress without the isntance name.
For example xxx.xxx.xxx.xxx instead of xxx.xxx.xxx.xxx\SQLEXPRESS
I can't believe it's such a stupid mistake ...

Cannot connect to sqlexpress

I just installed of SQL Server Management Studio Express 2012, and then I try to connect database engine with servername : ./sqlexpress, but it failed.
Its raised message like below :
TITLE: Connect to Database Engine
Cannot connect to ./sqlexpress.
ADDITIONAL INFORMATION:
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) (Microsoft SQL Server, Error: 3)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=3&LinkId=20476
The system cannot find the path specified.
Whats going wrong?
I've seen this in the past, most likely the wrong instance name or address. Since it is a local DB instance on your machine you will want to try connecting to (local)\SQLEXPRESS [This is the default SQL Express Instance]
If you are running a local instance of SQL Server you can just use localhost as the server name. Also you can try to remove the ./ before the server name.
If anyone else gets a failed to connect to server instance while trying to connect to a DB in C#, make sure you add localhost to the front of your database server address if you're on the same machine.
ie: myDatabase2012
should be put in as localhost\\myDatabase2012 (the second \ is needed to escape the first)

Cannot connect to sql server 2008 using JDBC

I have tried all the methods to connect to the server.I am using sql server 2008 on mixed authentication mode.I can login via the sql server management studio using the sa login.But when I try accessing the same db from my java program I get the following error:
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. ClientConnectionId:191d94bb-a55e-47a0-bb9f-b84638313cf4
This is my connectionstring:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl= "jdbc:sqlserver://localhost;databaseName=Northwind;user=sa;password=sa;";
I have accessed my database in the same way. One of my problems were that I hadn't enabled the port and IP for the database. Check these options in SQL Server Configuration Manager. Hope this helps =)