I'm debugging a database connection that I'm trying to make with System.Data.Linq.DataContext in C#.NET.
I basically create a context like this:
System.Data.Linq开发者_开发知识库.Mapping.MappingSource mappingSource = new AttributeMappingSource();
context = new DataContext("bogusconnectionstring", mappingSource);
I actually have that bogus connection string there at the moment.
The problem here is, is that I don't get any reason for the failed connection. I don't get an exception, no return or error codes, etc. currentContext.Connection.State reports being closed and context.DatabaseExists() says false, but I can't more information that that.
The documentation doesn't give any information about it either, nor does Google.
How do I get a normal exception or error code?
I would suggest, if only for debugging, handle the connection yourself for now, i.e.
using(var conn = new SqlConnection(connectionString))
{
conn.Open();
var context = new DataContext(conn, mappingSource);
// etc
}
this might at least get you started in terms of finding the problem at Open()
...
But it sounds to me like maybe the DB (/catalog) doesn't exist, or the account doesn't have access to it.
精彩评论