Dsnless connection in ASP.NET

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Dsnless connection in ASP.NET

  1. #1
    Join Date
    Dec 1969
    Posts
    165

    Default Dsnless connection in ASP.NET

    *<BR>I am trying to connect to an access database with asp.net.<BR><BR>Here is my connection string:<BR><BR>Const strConnStr as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Northwind.mdb")<BR><BR>I am getting the following error:<BR><BR>Compiler Error Message: BC30059: Constant expression is required.<BR><BR>Line 12: Sub BindData()<BR>Line 13: &#039;1. Create a connection<BR>Line 14: Const strConnStr as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Northwind.mdb")<BR>Line 15: <BR>Line 16: Dim objConn as New OleDbConnection(strConnStr)<BR> <BR>How can i fix this?<BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    2,885

    Default RE: Dsnless connection in ASP.NET

    Hello?<BR>Const requires a "constant" or "literal" value assigment; you are using a "variable" value assignment :)

  3. #3
    Join Date
    Dec 1969
    Posts
    165

    Default RE: Dsnless connection in ASP.NET

    How would i modify it?<BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    2,885

    Default RE: Dsnless connection in ASP.NET

    If you want to use a constant declaration, you need to supply a literal value. Otherwise, do not define it as a constant.


  5. #5
    Join Date
    Dec 1969
    Posts
    165

    Default RE: Dsnless connection in ASP.NET

    Got it. I was going from an example that I had.<BR><BR>This works:<BR><BR> Dim strConnStr as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Northwind.mdb")<BR>

  6. #6
    Join Date
    Dec 1969
    Posts
    2,885

    Default RE: Dsnless connection in ASP.NET

    Right! Do you understand why now?

  7. #7
    Join Date
    Dec 1969
    Posts
    165

    Default RE: Dsnless connection in ASP.NET

    I understand why, but not how to write it using a constant.

  8. #8
    Join Date
    Dec 1969
    Posts
    2,885

    Default RE: Dsnless connection in ASP.NET

    By definition, the word "Constant" inplies that it is "unchanging". Therefore you cannot assign a variable to a Constant. You must hard-code the value.

  9. #9
    Join Date
    Dec 1969
    Posts
    165

    Default RE: Dsnless connection in ASP.NET

    Can you show me an example?

  10. #10
    Join Date
    Dec 1969
    Posts
    2,885

    Default RE: Dsnless connection in ASP.NET

    Const strConnStr as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:SomeDirectoryASubDirectoryNorthwind.mdb" <BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •