NealR
NealR

Reputation: 10709

SqlConnection object in DLL throwing "Keyword not supported" exception on instantiation

I wrote a .dll that is to be used to connect to a SQL database. The code works fine when it was simply a class file in another Visual Studio project. However, now that I am attempting to use it as a .dll in another, this line throws an unhandled "ArgumentExcpetion":

        SqlConnection sqlConn = new SqlConnection(connString); 

What gets me is the text in the exception message box.

Keyword not supported: '<comp name>\sqlexpress;initial catalog'.

This is the same connection string I used in another program to connect to the SQL database on my local machine. I can look in the "Locals" window while I'm debugging in VS 2010, and The connection string looks exactly the same as it does in other projects I've used (in fact, I simply copied and pasted it)

"<comp name>\\SQLEXPRESS;initial catalog=AgentResources;integrated security=True;MultipleActiveResultSets=true"

Here is how the object is instantiated and the connection string added.

BatchRecord record = new BatchRecord("DEV", "TEST");

record.ConnString = "<comp name>\\SQLEXPRESS;initial catalog=AgentResources;integrated security=True;MultipleActiveResultSets=true";

Upvotes: 3

Views: 1007

Answers (1)

Blorgbeard
Blorgbeard

Reputation: 103535

That connection string is not valid. It should be

 Data Source=<comp name>\\SQLEXPRESS;

Upvotes: 5

Related Questions