?
Solved

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

Posted on 2012-03-15
4
Medium Priority
?
337 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 2000 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 2000 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

URL rewriting in AWS CloudFront

A quick how-to guide to implement with a Lambda function!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

719 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