Home All Groups Group Topic Archive Search About

Web.config: connection strings

Author
18 Mar 2006 5:12 PM
R.A.M.
Hello,

I am beginner.
Could you help me please how to connect to SQL Sever using connection
string in Web.config?
I have:
    <configuration>
    <appSettings/>
    <connectionStrings>
    DataSource=PC\SQLEXPRESS;User ID=sa;Password=sqlserver;
    Initial Catalog=DemoDotNET
    </connectionStrings>
and code behind:
    private string ConnectionString
    {
        get
        {
            SessionStateSection sss = new SessionStateSection();
            return sss.SqlConnectionString;
        }
    }
but I got ConnectionString == "data source=localhost;Integrated
Security=SSPI" instead of text from Web.config.
How to programme it corectly?
Thank you very much!

/RAM

Author
18 Mar 2006 5:53 PM
R.A.M.
That was a nonsense what I wrote.
I tried this way:

<connectionStrings>
    <MSAccess>Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=App_Data/DemoDotNET.mdb;User ID=;Password=;Mode=Share Deny
None</MSAccess>
    <SQLServer>DataSource=PC\SQLEXPRESS;User
ID=sa;Password=sqlserver;Initial Catalog=DemoDotNET</SQLServer>
</connectionStrings>

and code behind reading XML Web.config,
but my elements  <MSAccess> and <SQLServer> are considered invalid.
Could anyone tell me please how to do it corectly?
Thank you.
BTW, my SQL connection string is not OK, I think...

/RAM
Author
18 Mar 2006 6:14 PM
R.A.M.
I solved it.
THANX

AddThis Social Bookmark Button