KevinBurton

I am trying my first LINQ query and I am getting:

TestCase 'M:BuySeasonsBrowse.MainWindow.transactionButton_Click(System.Object,System.Windows.RoutedEventArgs)'

failed: Login failed for user ''. The user is not associated with a trusted SQL Server connection.

System.Data.SqlClient.SqlException: Login failed for user ''. The user is not associated with a trusted SQL Server connection.

at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)

at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)

at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)

at System.Data.SqlClient.SqlConnection.Open()

0 passed, 1 failed, 0 skipped, took 114.16 seconds

When I create the data context I give it a connection string which specifies all of the login credentials:

Transactions db = new Ttransactions("Data Source=sqlserver;Initial Catalog=transactions;UID=X;PWD=***");

The DB class 'Transaction was generated using SqlMetal and is derived from DataContext. Where else do I need to supply the SQL login credentials

Kevin



Re: LINQ Project General SQL login?

Caddre

If you are in a web application I have covered it in the thread below and if you are in Winform post again so I can give you the solution. Hope this helps.

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=2089731&SiteID=1






Re: LINQ Project General SQL login?

KevinBurton

This is a "winform". Really it is in the button event handler for a WPF application. Here is the code:

Code Block

// DataContext takes a connection string

BuySeasons_transactions db = new BuySeasons_transactions("Data Source=devbrain03;Initial Catalog=buyseasons_transactions;UID=x;PWD=x");

// Get a typed table to run queries

Table<PurchaseOrder> purchaseOrders = db.PurchaseOrders;

// Query for customers from London

var q =

from p in purchaseOrders

where p.Created > new DateTime(2007, 10, 1)

select p;

foreach (var order in q)

{

Console.WriteLine("TrackingNumber = {0}, Created = {1}, Status = {2}",order.TrackingNumber, order.Created, order.Status);

}

It faults in the foreach statement. I guess the login is delayed untill then.

Thank you.

Kevin





Re: LINQ Project General SQL login?

Adiel Sharabi

Hi

Try to qury like that:

var q =

from p in db.purchaseOrders

where p.Created > new DateTime(2007, 10, 1)

select p;

or more simple

var q = db.purchaseOrders.where(p=>p.Created > new DateTime(2007, 10, 1));

Adiel





Re: LINQ Project General SQL login?

KevinBurton

For the "simple" query I get a compile error:

Error 1 'System.Data.Linq.Table<BuySeasons.WebServices.DataAccess.PurchaseOrder>' does not contain a definition for 'where' and no extension method 'where' accepting a first argument of type 'System.Data.Linq.Table<BuySeasons.WebServices.DataAccess.PurchaseOrder>' could be found (are you missing a using directive or an assembly reference ) F:\Development\BuySeasonsBrowse\BuySeasonsBrowse\BuySeasonsBrowse\MainWindow.xaml.cs 36 39 BuySeasonsBrowse

For the first query, I get the same exception

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

Kevin





Re: LINQ Project General SQL login?

David Buchanan

I see failed UnitTest verbage:

>0 passed, 1 failed, 0 skipped, took 114.16 seconds

This makes me think that you might be running this as a UnitTest. Are you really hardcoding the credentials for your test, or are you loading the credentials via some config

Be aware that configs do not load the same when you are UnitTesting.





Re: LINQ Project General SQL login?

Caddre

If it is web service it is running in IIS which means you have to do what I posted in that thread. If you are not running in IIS you need to change SQL Server to mixed mode and enable the SA account because when you install SQL Server with Windows authentication the SA account is disabled. You need to enable it and try adding the account you are using in SQL Server on both the server level in Security and the security section within the database you are using. Another option is to configure delegation in SQL Server and Windows. Hope this helps.






Re: LINQ Project General SQL login?

KevinBurton

I am not running a web service and am not running under IIS. The SQL server is using mixed mode. SqlMetal used the same credentials and had no problem logining in. As was posted earlier the connection string is hard-coded with the UID and PWD in the connection string. I will have to check if the SA account is enabled or disabled. I don't have access to the SA account password. If the user account on the SQL server is "Me" then what needs to be done to configure delegation

Thank you.

Kevin





Re: LINQ Project General SQL login?

KevinBurton

The credentials are hard-coded in the connection string as I posted earlier.

Thank you.

Kevin





Re: LINQ Project General SQL login?

Caddre

You could run profiler to audit the failing login and here is Microsoft support solution to this problem.

http://support.microsoft.com/kb/889615






Re: LINQ Project General SQL login?

KevinBurton

I don't think this is the problem.

1) I know the SQL authentication has been turned on because as I stated before SQLMetal used these same credentials without an issue. I used SQLMetal from the same computer that I am trying to use LINQ now.

2) The exception indicates that

Login failed for user ''. The user is not associated with a trusted SQL Server connectionLogin failed for user ''. The user is not associated with a trusted SQL Server connection

This is not the user name supplied in the connection string. I have a non-blank user name hard-coded in the connection string.

3) I have tested this connection string using SQL Management Studio and I again have no problem.

Somehow LINQ is assuming Windows authentication and is not using the user name that I supplied with the connection string to login with.

Kevin





Re: LINQ Project General SQL login?

KevinBurton

FYI. I tried the following with the exact same connection string:

Code Block

SqlConnection connection = new SqlConnection(connectionString);

SqlCommand command = connection.CreateCommand();

command.CommandText = "SELECT COUNT(*) FROM PurchaseOrders WHERE Created > '10/1/2007'";

command.CommandType = CommandType.Text;

connection.Open();

Debug.WriteLine(string.Format("There are {0} orders", command.ExecuteScalar()));

connection.Close();

And there was not anexception like there was with the LINQ query.

Kevin





Re: LINQ Project General SQL login?

KevinBurton

This has to be a bug in the current version of LINQ. Do you know when the next build will be available

Thank you.





Re: LINQ Project General SQL login?


Re: LINQ Project General SQL login?

KevinBurton

I have been unable to find this "properties" dialog with Vista or Windows Server 2008 (Longhorn). How is delgation configured there

Thank you.