Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,459 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,806 people online right now. Registration is fast and FREE... Join Now!




SQL 2005 connection fail to asp.net page

 
Reply to this topicStart new topic

SQL 2005 connection fail to asp.net page

bmarthone
12 Aug, 2008 - 12:23 AM
Post #1

New D.I.C Head
*

Joined: 10 Dec, 2007
Posts: 5


My Contributions
Hey guys,

I'm trying to connect to a SQL 2005 database with a asp.net web page I created. I tried every thing that I could think of. I dis enable all the default settings on the database. Here is the code that is in the Web Config file which is suppose to connect my web page to the database:

<connectionStrings>
<add name="APPLEConnectionString"
connectionString="Data Source=****\SQLEXPRESS;Initial Catalog=C:\ASP.NET_WEBPAGE\APP_DATA\COLOR.MDF;User ID=******;Password=*********"
providerName="System.Data.SqlClient" />
</connectionStrings>


Thanks,
User is offlineProfile CardPM
+Quote Post

bmarthone
RE: SQL 2005 Connection Fail To Asp.net Page
12 Aug, 2008 - 12:24 AM
Post #2

New D.I.C Head
*

Joined: 10 Dec, 2007
Posts: 5


My Contributions
Hey guys,

I'm trying to connect to a SQL 2005 database with a asp.net web page I created. I tried every thing that I could think of. I dis enable all the default settings on the database. Here is the code that is in the Web Config file which is suppose to connect my web page to the database:

<connectionStrings>
<add name="APPLEConnectionString"
connectionString="Data Source=****\SQLEXPRESS;Initial Catalog=C:\ASP.NET_WEBPAGE\APP_DATA\COLOR.MDF;User ID=******;Password=*********"
providerName="System.Data.SqlClient" />
</connectionStrings>


Thanks,
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: SQL 2005 Connection Fail To Asp.net Page
12 Aug, 2008 - 07:25 AM
Post #3

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 363



Thanked: 19 times
Dream Kudos: 25
My Contributions
would you post the error that you are getting?

also, instead of putting the file name as the "Initial Catalog", try just using the Database name.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: SQL 2005 Connection Fail To Asp.net Page
12 Aug, 2008 - 07:38 AM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You also need to show us, other than the connection string in the web.config, how you're calling the connection string to connect to the database.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: SQL 2005 Connection Fail To Asp.net Page
12 Aug, 2008 - 07:56 AM
Post #5

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Please dont create duplicate topics. You have this same question asked in the Databases forum. Topics merged
User is offlineProfile CardPM
+Quote Post

bmarthone
RE: SQL 2005 Connection Fail To Asp.net Page
12 Aug, 2008 - 06:15 PM
Post #6

New D.I.C Head
*

Joined: 10 Dec, 2007
Posts: 5


My Contributions
Ok guys her is the code in my application page.
CODE

SqlDataSource NameColor = new SqlDataSource();
        NameColor.ConnectionString = ConfigurationManager.ConnectionStrings["AppleConnectionString"].ToString();
        NameColor.InsertCommandType = SqlDataSourceCommandType.Text;
        NameColor.InsertCommand = "INSERT INTO Name (Name, Color) VALUES (@Name, @Color)";
        NameColor.InsertParameters.Add("Name", TextBox1Name.Text);
        NameColor.InsertParameters.Add("Color", TextBox2Color.Text);

        int RowsAffected = 0;
        try
        {
            RowsAffected =NameColor.Insert();
        }
        catch (Exception ex)
        {
            Server.Transfer("Error.aspx");
        }
        finally
        {
            NameColor  = null;
        }
        if (RowsAffected != 1)
        {
            Server.Transfer("Error.aspx");
        }
        else
        {
            Server.Transfer("Successfull.aspx");
        }

User is offlineProfile CardPM
+Quote Post

divyapagidela
RE: SQL 2005 Connection Fail To Asp.net Page
12 Aug, 2008 - 09:57 PM
Post #7

New D.I.C Head
*

Joined: 22 Jul, 2008
Posts: 15



Thanked: 1 times
My Contributions
QUOTE(bmarthone @ 12 Aug, 2008 - 07:15 PM) *

Ok guys her is the code in my application page.
CODE

SqlDataSource NameColor = new SqlDataSource();
        NameColor.ConnectionString = ConfigurationManager.ConnectionStrings["AppleConnectionString"].ToString();
        NameColor.InsertCommandType = SqlDataSourceCommandType.Text;
        NameColor.InsertCommand = "INSERT INTO Name (Name, Color) VALUES (@Name, @Color)";
        NameColor.InsertParameters.Add("Name", TextBox1Name.Text);
        NameColor.InsertParameters.Add("Color", TextBox2Color.Text);

        int RowsAffected = 0;
        try
        {
            RowsAffected =NameColor.Insert();
        }
        catch (Exception ex)
        {
            Server.Transfer("Error.aspx");
        }
        finally
        {
            NameColor  = null;
        }
        if (RowsAffected != 1)
        {
            Server.Transfer("Error.aspx");
        }
        else
        {
            Server.Transfer("Successfull.aspx");
        }









Hiiiiiii
Try this code for connecting simple login page to the database using sessions
This code is only for Simple login page.............
I hope this may be helps u to understand a few

CODE

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class _Default : System.Web.UI.Page
{

    static SqlConnection con = new SqlConnection(@"Data Source=divya;Initial Catalog=divproject;Integrated Security=True");

    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Focus();
    
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        try
        {
            SqlDataAdapter da = new SqlDataAdapter("select * from login where userid like '" + TextBox1.Text + "' and password like '" + TextBox2.Text + "' ", con);
            DataSet ds = new DataSet();
            da.Fill(ds, "login");
            if (ds.Tables["login"].Rows[0][0] != null)
            {
                Session.Add("id", TextBox1.Text);

                Response.Redirect("welcome.aspx");

            }
        }
        catch
        {
            Response.Write("Login failed.........");
            //Response.Write("Enter correct username and password");
        }
  
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        //Application.
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
    
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox1.Focus();
    }
}



User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: SQL 2005 Connection Fail To Asp.net Page
13 Aug, 2008 - 07:04 AM
Post #8

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 363



Thanked: 19 times
Dream Kudos: 25
My Contributions
QUOTE(bmarthone @ 12 Aug, 2008 - 10:15 PM) *

Ok guys her is the code in my application page.
CODE

SqlDataSource NameColor = new SqlDataSource();
        NameColor.ConnectionString = ConfigurationManager.ConnectionStrings["AppleConnectionString"].ToString();
        NameColor.InsertCommandType = SqlDataSourceCommandType.Text;
        NameColor.InsertCommand = "INSERT INTO Name (Name, Color) VALUES (@Name, @Color)";
        NameColor.InsertParameters.Add("Name", TextBox1Name.Text);
        NameColor.InsertParameters.Add("Color", TextBox2Color.Text);

        int RowsAffected = 0;
        try
        {
            RowsAffected =NameColor.Insert();
        }
        catch (Exception ex)
        {
            Server.Transfer("Error.aspx");
        }
        finally
        {
            NameColor  = null;
        }
        if (RowsAffected != 1)
        {
            Server.Transfer("Error.aspx");
        }
        else
        {
            Server.Transfer("Successfull.aspx");
        }



now the next question is, what is actually happening? Is nothing getting inserted? Are you getting error messages? What is the actual problem?

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:07PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month