Indeed, indeed, do verify that TCP / IP is enabled on your local SQLEXPRESS instance.
Follow these steps to verify:
- Open " Sql Server Configuration Manager " in the "Start" menu \ Programs \ Microsoft SQL Server 2012 \ Configuration Tools \ "
- Expand SQL Server Network Configuration
- Go to "Protocols for SQLEXPRESS"
- Enable TCP / IP
If you are having problems, check this blog post for more details, as it contains screenshots and more.
Also check if the Windows Server Browser service is activated and working :
- Go to Control Panel โ Administrative Tools โ Services
- Open SQL Server Service Server and enable it (make it manual or automatic, depending on your needs)
- Run it.
What is it.
After installing the new local SQLExpress, all I had to do was enable TCP / IP and start the SQL Server Browser service.
Below is the code I use to test the local SQLEXPRESS connection. Of course, you should change the IP, database_name, and user / password as needed .:
import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; public class JtdsSqlExpressInstanceConnect { public static void main(String[] args) throws SQLException { Connection conn = null; ResultSet rs = null; String url = "jdbc:jtds:sqlserver://127.0.0.1;instance=SQLEXPRESS;DatabaseName=master"; String driver = "net.sourceforge.jtds.jdbc.Driver"; String userName = "user"; String password = "password"; try { Class.forName(driver); conn = DriverManager.getConnection(url, userName, password); System.out.println("Connected to the database!!! Getting table list..."); DatabaseMetaData dbm = conn.getMetaData(); rs = dbm.getTables(null, null, "%", new String[] { "TABLE" }); while (rs.next()) { System.out.println(rs.getString("TABLE_NAME")); } } catch (Exception e) { e.printStackTrace(); } finally { conn.close(); rs.close(); } } }
And if you are using Maven, add this to your pom.xml:
<dependency> <groupId>net.sourceforge.jtds</groupId> <artifactId>jtds</artifactId> <version>1.2.4</version> </dependency>
acdcjunior Mar 15 '13 at 12:40 2013-03-15 12:40
source share