Reputation: 855
Is it possible to access the Data Connection added to the project in the code?
I know that it is possible to access DataSets created using visual designer but I would like to access the connection only.
Edit:
It is possible to add Data Connection to the project in VS2008 via Tools > Connect to Database.
I would like to access this connection as an object in my code so that I would not have to specify connection string by myself.
Upvotes: 4
Views: 10837
Reputation: 12795
I don't think you can directly use the connection created by the IDE as if it were one of your project's settings. However, the IDE provides similar functionality through the project properties.
How you get to the properties varies slightly on which language/default configuration you are using. But in general you should be able to try these steps and see if they provide the functionality you wanted:
Now you should be able to access this connection string from your project code.
VB.Net:
Dim cs = My.Settings.ConnectionString
C#:
var cs = Properties.Settings.Default.ConnectionString;
Upvotes: 6