Reputation: 465
I like to read from database using Linq to SQL. However in this method throw exception
public string[] readFromAbbrevationsPerson()
{
string[] resultAbbrevationsPerson = new string[10000];
DataClassesDataContext db = new DataClassesDataContext("NERMacedonianConnectionString");
var query = from abb in db.abbrevationsPersons
select abb.abbrevationsPerson1;
int i = 0;
foreach (string noun in query)
resultAbbrevationsPerson[i++] = noun;
return resultAbbrevationsPerson;
}
in the foreach statement.The exception is Invalid operation the connection is closed. I made refresh in VS 2010 to the server and I made refresh in SQL Management studio.Ichecked the status of the server is running.
Upvotes: 3
Views: 3778
Reputation: 10950
You need to pass the full connection string to the constructor for DataClassesDataContext(string connection)
, unless you've created your own constructor which just takes a value like what you've entered. The exception in this case is not very helpful in determining the cause.
Upvotes: 2