OK... I have a database and some ASPX files.... how can I connect the 2 together? BTW, I am using Microsoft Visual Studio 2008 to edit the ASPX files and Microsoft Office Access 2007 foir the DB files.
you have to define it in the webconfig file, then call it from your code. here is the script ( Config File): <configuration> <connectionStrings> <add name="dbcon" connectionString="Server=MyServer; Database=databasename; User Id=username; password= Pass" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration> and the usage: string dbConn = ConfigurationManager.ConnectionString["dbcon"].ToString(); this is for SQL Sever database. For Access Database change the providerName to: System.Data.OleDb and the connectionString to the physical path of your access file.
This will help you for sure. just add this code in Web.config <configuration> <appSettings> <add key="Constr" value="User ID=sa; Password=xyz;Data Source=xyz;Initial Catalog=xyz; " /> </appSettings> then here is the code to established the connection to database. private string ConnString() { try { return ConfigurationSettings.AppSettings["Constr"].ToString(); } } catch ( Exception e ) { throw (e); //return e.ToString (); } finally{} } here is the code block to execute reader. public SqlDataReader ReturnDataReader (string Sql) { try { objConn = new SqlConnection(this.ConnString()); objConn.Open (); SqlCommand myCommand=new SqlCommand (Sql,objConn ); aReader=myCommand.ExecuteReader(); return aReader; } catch (Exception ex ) { throw (ex); } } Let me know in case of any issue(s).