0

I keep getting this error: Format of the initialization string does not conform to specification starting at index 0.

This line of code:

using (OleDbConnection conn = new OleDbConnection("PayrollSystem_DBConnectionString"))

I think I need sql statements instead of Ole, I'm not sure.

Here is my form html code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:PayrollSystem_DBConnectionString %>" 
    ProviderName="<%$ ConnectionStrings:PayrollSystem_DBConnectionString.ProviderName %>"

Here is my frmManageUsers code:

public partial class frmManageUsers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void btnAddUser_Click1(object sender, EventArgs e)
    {
                //string userName, userPassword;



        if (txtUserName.Text == "" || txtUserName.Text == null)
        {
            lblError.Text = ("User Name may not be empty");
            lblError.ForeColor = System.Drawing.Color.Red;
            return;
        }
       // else

           // userName = (txtUserName.Text);


        if (txtPassword.Text == "" || txtPassword.Text == null)
        {
            lblError.Text = ("Password may not be empty");
            lblError.ForeColor = System.Drawing.Color.Red;
            return;
        }
        //else
           // userPassword = (txtPassword.Text);

        using (OleDbConnection conn = new OleDbConnection("PayrollSystem_DBConnectionString"))
            {
                string insert = "Insert INTO tblUserLogin (UserName, UserPassword, SecurityLevel) Values (@UserName, @UserPassword, @SecurityLevel)";
                OleDbCommand cmd = new OleDbCommand(insert, conn);
                cmd.Parameters.Add("@UserName", txtUserName.Text);
                cmd.Parameters.Add("@UserPassword", txtPassword.Text);
                cmd.Parameters.Add("@SecurityLevel", drpdwnlstSecurityLevel.SelectedValue);  
                cmd.ExecuteNonQuery();      
            }

        Session["UserName"] = txtUserName.Text;
        Session["Password"] = txtPassword.Text;
        Session["SecurityLevel"] = drpdwnlstSecurityLevel.SelectedValue;
        Server.Transfer("frmManageUsers.aspx");

        //Server.Transfer("grdUserLogin"); 

    }
    protected void drpdwnlstSecurityLevel_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}
3
  • what's your connection string look like? Commented Nov 29, 2011 at 23:12
  • @jim: <add name="PayrollSystem_DBConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\LOCATION HERE\PayrollSystem_DB.mdb" Commented Nov 29, 2011 at 23:14
  • is this a REAL payroll system for a REAL place or is this for academia? Commented Nov 30, 2011 at 0:12

2 Answers 2

1

OleDbConnection takes the actual connection string, not the NAME of the connection string. You have to get the connection string from the Configuration using ConfigurationManager.ConnectionStrings["PayrollSystem_DBConnectionString"].ConnectionString and pass that to OleDbConnection

Sign up to request clarification or add additional context in comments.

4 Comments

@Mike - Exactly as I said, you pass it to your OleDbConnection. I'm not sure how I could say it any clearer.
using (OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["PayrollSystem_DBConnectionString"].ConnectionString))
@Mystere Man: I don't understand this stuff. It has taken me a long time just to get where I am. So I'm assuming this line goes before OleDbConnection right? I did it like that and the whole line is an error. Visual Studio 3.5 isn't recognizing "ConfigurationManager".
@mike are you doing this for real life? or is a school project?
0

Also, if you're using a 64-bit system, you need to change the connection string to use the new provider, Microsoft.ACE.OLEDB.14.0

You can download it here:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.