Solved

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

Posted on 2012-03-15
4
329 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
  • 2
  • 2
4 Comments
 
LVL 74

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 74

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now