Solved

problem with connecting sq lserver using windows authentication in asp.net3.5

Posted on 2012-03-15
4
336 Views
Last Modified: 2012-04-19
Hi
I am creating login page in asp.net ,c#.
and I am using Sql server2008, using windows authentication.

Here it is failed to open sql server
here is my code

 
protected void login_Click(object sender, EventArgs e)
            {

                SqlConnection con = new SqlConnection(@"User id=lucky\Dell;Password=;Server=lucky;Database=tbllogin");
               [u] con.Open();[/u]
                SqlCommand cmd;
                SqlDataReader dr;
                cmd = new SqlCommand("Select * from tbl_login where username='" + TextBox1.Text+ "'", con);

                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    Response.Write("wrong details");

                }
                else
                {
                    Response.Redirect("Default.aspx");

                }

                con.Close();

            }

Open in new window


can any one help me how to connect with sqlserver using windws authentication from .net.?
is there anything wrong with my connectionstring?
0
Comment
Question by:lucky20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 500 total points
ID: 37727456
is there anything wrong with my connectionstring?
I think so. Please review http://www.connectionstrings.com/sql-server-2008 and find the string which matches your environment (probably the first one on the list).
0
 
LVL 1

Author Comment

by:lucky20
ID: 37727853
Sorry ..I didn't understand that link..
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 37727875
In order to connect to a database, you must have a connection string, and it must be configured correctly. You are using a connection string in line 4 of your code posting (it's the thing between the double-quotes). I don't believe you have set up your connection string properly. The link I gave you is a link to a site which keeps track of various connection string for various database platforms. I provided you with link to the SQL Server 2008 page. The things in the gray/blue boxes are the various connection strings you might try. They are generic, so you will have to change the parts of the string to match your environment (e.g. change "Inital Catalog=myDataBase" to "Initial Catalog=lucky"). I believe the first entry on that page is the one that will get you going. Just be sure to change the parts to match your server.

"Data Source" is the server name and instance name of your database. It should be of the form:  server\instance
"Initial Catalog" is the name of the database as found at "Data Source". If you view your database in something like SQL Server Management Studio, a "Data Source" would be the name you find next to the little database icon (the yellow cylinder).
0
 
LVL 1

Author Comment

by:lucky20
ID: 37730146
yes I have used that code.

Still getting the error as " SqlException was unhandled by user".
error description:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

My code:
SqlConnection con = new SqlConnection(@"Data Source =c:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL ; Initial Catalog = tbllogin; User Id =lucky\Dell ; Password = ");
                SqlCommand cmd;

Open in new window

0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question