Solved

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

Posted on 2012-03-15
4
333 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 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…

860 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