Thursday, June 30, 2011

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


Problem:
Connecting to SQL Server with a query in SQL Server Management Studio, you get “Login failed for user xxxx.  The user is not associated with a trusted SQL Server connection.”












Solution:
Open Microsoft SQL Server Management Studio.
Connect to your sql instance.  Right click the instance name in the Object Explorer window and select properties.





Select SQL Server and Windows Authentication mode and click OK.

!Very Important!  Restart SQL Server for this setting to take effect.

Saturday, April 2, 2011

Problem in mapping fragments starting at line nnn:All the key properties (xxxx.column) of the EntitySet xxxx must be mapped to all the key properties

Problem:

Error 3003: Problem in mapping fragments starting at line 257:All the key properties (table.column) of the EntitySet table must be mapped to all the key properties (table.column, table.column) of table table.


Solution:

Select the column giving you problems, hit F4 for properties, and change Nullable from (None) to False.




















Wednesday, March 30, 2011

Index (zero based) must be greater than or equal to zero and less than the size of the argument list

Problem:
System.FormatException was unhandled by user code
  Message=Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
  Source=mscorlib
  StackTrace:
       at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
       at System.String.Format(IFormatProvider provider, String format, Object[] args)
       at System.String.Format(String format, Object arg0)
       at MultiThreadedDbSeeder.Program.<Main>b__0(Int32 i) in C:\xxxx\Program.cs:line 22
       at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.b__c()
  InnerException:

Offending Line:
SqlCommand cmd = new SqlCommand(string.Format(@"insert into table_1 (vch_value) values('{1}')", "the value of i is " + i));

Solution:
Don’t forget that string.Format uses a zero based index.
Fixed Code:
SqlCommand cmd = new SqlCommand(string.Format(@"insert into table_1 (vch_value) values('{0}')", "the value of i is " + i));