Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a bulk mail project in project mail ids retrieve directly from access database but i am facing a problem in database connection please Help me

My code in like this
C#
{
    ArrayList Email_List = new ArrayList();
    int i = 0;
    string email;
    string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=//db.accdb;Persist Security Info=True;";
    
    protected void Page_Load(object sender, EventArgs e)
    {
    
    } 
    protected void btn1_Click(object sender, EventArgs e)
    {
        OleDbConnection cn = new OleDbConnection(connectString);
        cn.Open();
        OleDbCommand cmd = new OleDbCommand("Select * from db.accdb", cn);
        OleDbDataReader accessemp_email = cmd.ExecuteReader();
        while (accessemp_email.Read())
        {
            email = accessemp_email.GetValue(i).ToString();
            Email_List.Add(email); 
            i = i + 1 - 1;
        }
        accessemp_email.Close();
        cn.Close(); 
        SendMail();
    }
}
Posted
Updated 3-May-12 13:56pm
v3
Comments
nani1233 3-May-12 6:36am    
Server Error in '/BulkEmail' Application.
The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.

Source Error:

Line 30: protected void btn1_Click(object sender, EventArgs e)
Line 31: {
Line 32: conn.Open();
Line 33: OleDbCommand cmd = new OleDbCommand("Select * from Empdata", conn);
Line 34: OleDbDataReader accessEmpdata = cmd.ExecuteReader();


Source File: c:\Documents and Settings\IRIDGE\Desktop\Mail Project\Ganeshji_Articles_634180351291247734_BulkEmail (1)\New Folder\BulkEmail\Default.aspx.cs Line: 32

Stack Trace:

[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.OleDb.OleDbConnection.PermissionDemand() +995383
System.Data.OleDb.OleDbConnectionFactory.PermissionDemand(DbConnection outerConnection) +20
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.OleDb.OleDbConnection.Open() +40
_Default.btn1_Click(Object sender, EventArgs e) in c:\Documents and Settings\IRIDGE\Desktop\Mail Project\Ganeshji_Articles_634180351291247734_BulkEmail (1)\New Folder\BulkEmail\Default.aspx.cs:32
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565





I am getting error massage
ManavGuru 3-May-12 6:53am    
write connection string on page load or button click event

I think that you should use the connection string from Connection strings for Access 2007[^], as reported in the preceding solution, using the Server.MapPath method for the path to the accdb file.
The resulting string should be something like:
C#
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("/db.accdb") + ";Persist Security Info=False;"

It's possible that the oledb driver is not installed on your system. In that case you must download it from 2007 Office System Driver: Data Connectivity Components[^] and install it.
 
Share this answer
 
use Provider=Microsoft.ACE.OLEDB.12.0;Data
look at following link
http://www.connectionstrings.com/
 
Share this answer
 
Comments
nani1233 3-May-12 6:36am    
when i use this code iam getting a error above mentioned

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900