Database Connectivity with ASP.Net

Discussion in 'Databases' started by virender.ets, Feb 8, 2011.

  1. #1
    I have visual studio 2008 and sql server 2005.Both of the softwares are going to be well installed but there is a problem in database connectivity in between when I am writing a program to access the data through SQL server 2005. THis kind of mentioned error is displaying:
    there is a problem in login with this user name
     
    virender.ets, Feb 8, 2011 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Given it is a web application your web.config file should have the db connection string something like:
    
        <connectionStrings>
            <add name="NameOfCS" connectionString="Data Source=LocalHost;Initial Catalog=DBName;Persist Security Info=True;User ID=Username;Password=XXX"
                providerName="System.Data.SqlClient" />
        </connectionStrings>
    
    Code (markup):
    Using CodeBehind you simply use it as:
           Dim SQL As New SqlCommand
            SQL.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("NameOfCS").ConnectionString)
    
    Code (markup):
    Or for a component:
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:NameOfCS %>"  />
    
    Code (markup):
    If the db is remote, ensure it allows remote connections. If it is local, make sure it has the right ports open or specify the open ports in the connection string
     
    AstarothSolutions, Feb 8, 2011 IP
  3. prptl709

    prptl709 Guest

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks but I want to know deeply about how actually database fields are fetched? please help me.
     
    prptl709, Feb 23, 2011 IP