views:

80

answers:

2

I'm using following code to connect with Sql Server 2008:

Connection con = null;
CallableStatement stmt = null;
ResultSet rs = null;

try
{
    SQLServerDataSource ds = new SQLServerDataSource();
    ds.setIntegratedSecurity(false);
    ds.setServerName("localhost");
    ds.setInstanceName("MSSQLSERVER2008");
    ds.setPortNumber(1433);  
    ds.setUser("televic-edu3-dev");
    ds.setPassword("internal");
    ds.setDatabaseName("televic-edu3-dev");
    con = ds.getConnection();
    ...

It gives me following error:

Login failed for user 'televic-edu3-dev'. The user is not associated with a trusted SQL Server connection.

Mixed mode is enabled on my SqlServer instance. I already tried connecting to my SqlServer instance with the same credentials, which works. In .NET, it does work with a connectionString which has the same credentials... So what am I doing wrong?

This is the connectionString from .NET:

TLV-EDU-LIC\MSSQLSERVER2008;Password=internal;Persist Security Info=True;User ID=televic-edu3-dev;Initial Catalog=televic-edu3-dev

I also tried this by the way, which gives me the same error (which is logical):

Connection con = null;
Statement stmt = null;
ResultSet rs = null;

try
{
    String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
    "instanceName=MSSQLSERVER2008;databaseName=televic-edu3-dev;
        userName=televic-edu3-dev;password=internal;";

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    con = DriverManager.getConnection(connectionUrl);
A: 

You're using domain (Windows username) authentication rather than DB authentication. Ensure that the JVM is running with the same Windows username and thus not as a system service. If that's not an option, use DB authentication instead.

BalusC
ds.setIntegratedSecurity(false);
Lieven Cardoen
Didn't see that. I was just translating the error message into easy-to-understand words :) Odd that omitting the portnumber changes things a lot.
BalusC
A: 

Well, omitting the ds.setPortNumber(1433); makes it work. Don't know why... my sqlserver instance is running on port 1433.

Lieven Cardoen