尝试通过LAN访问asp.net应用程序时,SQL连接失败.请帮忙 [英] SQL connection failed when try to access asp.net application over LAN. please help

查看:51
本文介绍了尝试通过LAN访问asp.net应用程序时,SQL连接失败.请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,先生,

祝大家有美好的一天!
我试图通过局域网(另一台计算机)测试我的asp.net应用程序,但是它无法通过局域网(Windows身份验证)连接到sql server 2005 Express Edition.我的第一个Web表单是Login.aspx页面. (但是在我的开发环境中,连接成功,我的计算机上本地安装了sql server 2005 Express Edition),下面是我的代码:(谢谢您)

Hi Sir,

Good day to all!
I tried to test my asp.net application over LAN (other computer) but it''s failed to connect to the sql server 2005 express edition over LAN (windows authentication). My first webform is the Login.aspx page. (but in my development environment it was connection success, my sql server 2005 express edition installed locally on my computer) Below is my code: (Thank you in Advance)

private bool ValidateUser(string userName, string passWord)
  {
      SqlConnection conn;
      SqlCommand cmd;
      string lookupPassword = null;

      // Check for invalid userName.
      // userName must not be null and must be between 1 and 15 characters.
      if ((null == userName) || (0 == userName.Length) || (userName.Length > 15))
      {
          System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of userName failed.");
          return false;
      }

      // Check for invalid passWord.
      // passWord must not be null and must be between 1 and 25 characters.
      if ((null == passWord) || (0 == passWord.Length) || (passWord.Length > 25))
      {
          System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of passWord failed.");
          return false;
      }

      try
      {
          // Consult with your SQL Server administrator for an appropriate connection
          // string to use to connect to your local SQL Server.
          conn = new SqlConnection("server=GD467887\\SQLEXPRESS;Integrated Security=SSPI;database=Irocdb");
          conn.Open();

          // Create SqlCommand to select pwd field from users table given supplied userName.
          cmd = new SqlCommand("Select pwd from users where uname=@userName", conn);
          cmd.Parameters.Add("@userName", SqlDbType.VarChar, 25);
          cmd.Parameters["@userName"].Value = userName;

          // Execute command and fetch pwd field into lookupPassword string.
          lookupPassword = (string)cmd.ExecuteScalar();

          // Cleanup command and connection objects.
          cmd.Dispose();
          conn.Dispose();
      }
      catch (Exception ex)
      {
          // Add error handling here for debugging.
          // This error message should not be sent back to the caller.
          System.Diagnostics.Trace.WriteLine("[ValidateUser] Exception " + ex.Message);
      }

      // If no password found, return false.
      if (null == lookupPassword)
      {
          // You could write failed login attempts here to event log for additional security.
          return false;
      }

      // Compare lookupPassword and input passWord, using a case-sensitive comparison.
      return (0 == string.Compare(lookupPassword, passWord, false));

  }

推荐答案

尝试使用SQL身份验证或模仿 [^ ]您的Web应用程序与具有足够权限来连接的本地用户一起使用到数据库(您的用户ID可能很好).
Try using SQL authentication or impersonate[^] your web application with a local user having sufficient rights to connect to database (your user id might be fine).


这篇关于尝试通过LAN访问asp.net应用程序时,SQL连接失败.请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆