Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

971 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