CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Problem connecting to a MS Sql Server 2012 instance when building project.

  1. #1
    Join Date
    Jun 2016
    Posts
    1

    Problem connecting to a MS Sql Server 2012 instance when building project.

    I'm having what seems like a fairly simple issue, but I can't for the love of me find out what's wrong.

    This is my url and connection string. Fairly standard.
    Code:
    String DBUsername = "sa";
            String DBPassword = "password";
            String DBPath = "jdbc:sqlserver://127.0.0.1\\ThisDatabase:1433";
            serverLog = new FileAccess("ServerLog.txt");
            serverLog.write("ServerLog");
            gameDB = new Database(DBPath, DBUsername, DBPassword);
    The Database class constructor initializes a Connection object using the following:
    Code:
    try {
                DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
                con = DriverManager.getConnection(host, name, password);
                serverLog.write("successfully connected to DB");
            }
            catch ( Exception err ) {
               System.out.println( err.getMessage( ) );
               serverLog.write(err.getMessage());
            }
    Now, here's my issue:
    The above code works. Perfectly fine.
    It allows me to interact with my database created using the SQL Server Express 2012 installed on my machine.
    That is, until I try to build the project using NetBeans 8.1. Executing the resulting JAR hands me this nice little error:
    «The TCP/IP connection to the host 127.0.0.1, port 1433 has failed. Error: "Unable to establish loopback connection. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".»

    I already think the problem isn't with the Java code itself, but didn't know where else I should post my query.

  2. #2
    Join Date
    Jul 2016
    Posts
    2

    Re: Problem connecting to a MS Sql Server 2012 instance when building project.

    Hi

    For what I see from your code you are right, the better option is that your firewall is doing this because the isn't allowed or th service of sql server is off

    I hope to be of help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)