locked
Database connection help, retreive email addresses from database, no connection. RRS feed

  • Question

  • User-1240662851 posted

    Iam doing bulkmail Project in this the email ids retrive from MS accsess database but i could not open the connection and my code is like this

    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();
    }

    pelease Help Me

    Regards,

    PrakashCry

     

    Tuesday, May 1, 2012 8:13 AM

Answers

  • User-1199946673 posted

    string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=//db.accdb;Persist Security Info=True;";

    The Jet.Oledb.4.0 driver doesn't work for access 2007 (.accdb), only for Access 2003 (*.mdb) and below.

    So either convert your .accdb file to an .mdb, or use the new ACE 12.0 driver. Note that this driver is NOT installed by default on a Windows server, so it might not be available in you production environment!

    http://www.mikesdotnetting.com/Article/78/AccessDataSource-SqlDataSource-and-connecting-to-Access-databases-in-ASP.NET 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 1, 2012 8:34 AM
  • User-718146471 posted

    Although the best option I recommend is turn your access db into a sql db using the upsizing wizard. Then you are able to take full advantage of SQL Server, stuff like Stored Procs and such are not available in Access :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 3, 2012 6:19 AM

All replies

  • User-718146471 posted

    I think the problem is your connectionstring, please post it so we can have a look. It should look like this:

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\myDatabase.mdb;User Id=admin;Password=;

    Tuesday, May 1, 2012 8:15 AM
  • User-1240662851 posted

    {
    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();
    }

    Tuesday, May 1, 2012 8:17 AM
  • User1304301175 posted

    check this thread this may help you

    http://forums.asp.net/t/1571690.aspx/1

    Tuesday, May 1, 2012 8:17 AM
  • User-718146471 posted

    string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=//db.accdb;Persist Security Info=True;";

    Check your conn string against these samples shown on connectionstrings.com

    http://connectionstrings.com/access-2007

    Tuesday, May 1, 2012 8:27 AM
  • User-718146471 posted

    string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=//db.accdb;Persist Security Info=True;";

    Umm, why are you using " + " in the middle of the connection string? It should be like this:

    string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=//db.accdb;Persist Security Info=True;";

    Tuesday, May 1, 2012 8:29 AM
  • User-1199946673 posted

    string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=//db.accdb;Persist Security Info=True;";

    The Jet.Oledb.4.0 driver doesn't work for access 2007 (.accdb), only for Access 2003 (*.mdb) and below.

    So either convert your .accdb file to an .mdb, or use the new ACE 12.0 driver. Note that this driver is NOT installed by default on a Windows server, so it might not be available in you production environment!

    http://www.mikesdotnetting.com/Article/78/AccessDataSource-SqlDataSource-and-connecting-to-Access-databases-in-ASP.NET 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 1, 2012 8:34 AM
  • User-1240662851 posted

    Thnaks my dear thank u so much Smile

    Tuesday, May 1, 2012 8:37 AM
  • User-1240662851 posted

    This is the error massiage evry time iam getting while debuging

    Server Error in '/BulkEmail_test' Application.


    Not a valid file name.

    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.Data.OleDb.OleDbException: Not a valid file name.

    Source Error:

    Line 30:     {
    Line 31:         OleDbConnection cn = new OleDbConnection(connectString);
    Line 32: cn.Open(); Line 33:         OleDbCommand cmd = new OleDbCommand("Select emp_email from Emails_be.laccdb", cn);
    Line 34:         OleDbDataReader accessemp_email = cmd.ExecuteReader();
    
    
    Tuesday, May 1, 2012 8:51 AM
  • User-718146471 posted

    Try to make sure that your filename for the database is correct and you're using the correct path. Like this:

    string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.accdb;Persist Security Info=True;"; if its in the root,

    in the data directory:

    string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|db.accdb;Persist Security Info=True;";

    Tuesday, May 1, 2012 10:05 AM
  • User3866881 posted

    Try to make sure that your filename for the database is correct and you're using the correct path. Like this:

    string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.accdb;Persist Security Info=True;"; if its in the root,

    in the data directory:

    string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|db.accdb;Persist Security Info=True;";

    My addition——

    For accdb database,I think it's better to use ACE driver instead of Oledb4.0。For connection string,you can find more at:

    http://www.connectionstrings.com/access-2007

    Wednesday, May 2, 2012 9:39 PM
  • User-718146471 posted

    His table name just looks off to me as well:

    ("Select emp_email from Emails_be.laccdb", cn);

    Shouldnt that be just Emails_be?

    Thursday, May 3, 2012 6:18 AM
  • User-718146471 posted

    Although the best option I recommend is turn your access db into a sql db using the upsizing wizard. Then you are able to take full advantage of SQL Server, stuff like Stored Procs and such are not available in Access :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 3, 2012 6:19 AM
  • User3866881 posted

    OleDbCommand cmd = new OleDbCommand("Select emp_email from Emails_be.laccdb", cn);

    You should select from a DataTable's Name instead of a database's name at "Emails_be.laccdb"……

    Sunday, May 6, 2012 9:55 PM