AndyGB4
Posts: 122
|
Posted: 03/18/2013, 1:05 PM |
|
Hi,
In a Before Show event, I'm doing some calculations and I need to connect to a database.
I've figured out how to connect, but in doing it my way, I can foresee many problems arising if I had to change my connection string in the future.
Here's what I use:
SqlConnection thisConnection = new SqlConnection(@"Network Library=DBMSSOCN;Persist Security Info=False;
User ID=myUserName;database=myDatabaseName;Data Source=DataSource;Password=myPassword");
thisConnection.Open();
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT * FROM tableName;";
SqlDataReader thisReader = thisCommand.ExecuteReader();
If ever I'd change my password or username, I'd have to find every single occurrence of this code to change it! There must be a way I could connect to a table without having to put in the connection string every time, right? Does anyone know how I can do this?
Thank you!
|
|
|
cvboucher
Posts: 191
|
Posted: 03/18/2013, 2:57 PM |
|
There's a few options under the Working With Databases section.
http://code.google.com/p/inmotion-framework/wiki/HowTo
If you're going to do something like this in more then a few places you may want to look at this execellent tool to generate a BusinessObject layer. It's open source so it's free but it does require Visual Studio to compile the layer. You'll also have to make some modifications to your web.config and global.asax in your CCS app.
http://www.entityspaces.net
Craig
|
|
|
AndyGB4
Posts: 122
|
Posted: 03/18/2013, 4:18 PM |
|
Thanks cvboucher, I figured out a way to do it so that I don't have to put my connection string each time, which is nice, but this entity stuff looks good. I'll have to check it out!
|
|
|
|