Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
linenumberstrue
import java.sql.*;
import net.sourceforge.jtds.jdbc.*;

public class Main {
    public static void main(String[] args)
       throws SQLException {
        System.setProperty("javax.net.ssl.trustStore", "/Users/mpoddar/IdeaProjects/keystore" );
        System.setProperty("javax.net.ssl.trustStorePassword","keystorepassword");
        String connectionUrl =
                "jdbc:jtds:sqlserver://sqlseclab-lsnr1.its.yale.edu:1433/master;" +
                        "domain=yale;user=ap349;password=password;useNTLMv2=true;" +
                        "ssl=authenticate";
        Connection connection = DriverManager.getConnection(connectionUrl);
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select GetDate()");
        while (resultSet.next()) {
            System.out.println(resultSet.getString(1));
        }
    }
}

 

cd) Connect with C#

Code Block
themeDJangoRDark
languagec#
linenumberstrue
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;

namespace SecureSQL
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SqlConnection connection = new SqlConnection())
            {
                connection.ConnectionString = "Server=sqlseclab-lsnr1.its.yale.edu;" + 
                                              "Initial Catalog=master;" +
                                              "Integrated Security=true;" +
                                              "Encrypt=True;TrustServerCertificate=False";
                connection.Open();
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "select GetDate()";
                    command.CommandType = CommandType.Text;

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Console.WriteLine("{0}", reader[0]);
                        }
                    }
                }

                Console.ReadLine();
            }
        }
    }
}


e) Connect with Linked server

Code Block
themeRDark
languagesql
linenumberstrue
USE [master]
GO

EXEC master.dbo.sp_addlinkedserver 
      @server = N'SECURE_LINKED_SERVER', 
	  @srvproduct=N'', 
	  @provider=N'SQLNCLI11', 
	  @datasrc=N'sqlseclab-lsnr1.its.yale.edu', 
	  @provstr=N'Encrypt=yes;Trust Server Certificate=False', 
	  @catalog=N'master'

EXEC master.dbo.sp_addlinkedsrvlogin 
      @rmtsrvname=N'SECURE_LINKED_SERVER',
	  @useself=N'False',
	  @locallogin=NULL,
	  @rmtuser=N'sa',
	  @rmtpassword='########'

GO

 

f) Connect with ODBC Data Source

Image Added

Image Added

Image Added

Image Added

Image Added

Image Added

Image Added

Image Added