CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP.NET - InMotion Framework

 How to connect to a Database in the code

Print topic Send  topic

Author Message
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!
View profile  Send private message
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
View profile  Send private message
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!

View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.