查看: 935|回复: 5
|
ASP.net的一个error.
[复制链接]
|
|
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: ExecuteReader: Connection property has not been initialized.
- Line 31: cmd.Parameters.Add("@password", System.Data.Odbc.OdbcType.VarChar, 128).Value = FormsAuthentication.HashPasswordForStoringInConfigFile(Password.Value, "md5"); // Or "sha1"
- Line 32: MyConnection.Open();
- Line 33: OdbcDataReader Reader = cmd.ExecuteReader();
- Line 34: if (Reader.Read())
- Line 35: {
复制代码
line 33 有一个error.
请问个位大大,有谁知道吗?
谢谢。 |
|
|
|
|
|
|
|
发表于 15-3-2006 01:18 PM
|
显示全部楼层
test your stoerd procedures in query analyzer....
make sure your stoerd procedures do not have any error...
make sure your database connection is connected... |
|
|
|
|
|
|
|
发表于 15-3-2006 01:24 PM
|
显示全部楼层
可以把你的code scroll上一点吗?
怀疑你没有assign connection 给cmd 。 。 。
应该不是sp 的问题 。 。 。 |
|
|
|
|
|
|
|

楼主 |
发表于 16-3-2006 09:12 AM
|
显示全部楼层
- private void btnLogin_Click(Object sender, EventArgs e)
- {
- FormsAuthentication.Initialize();
- string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
- "SERVER=localhost;" +
- "DATABASE=aspnet;" +
- "UID=root;" +
- "PASSWORD=chen1983;" +
- "OPTION=3";
- OdbcConnection MyConnection= new OdbcConnection(MyConString);
- OdbcCommand cmd = new OdbcCommand();
- cmd.CommandText = "SELECT roles FROM users WHERE username=@username " + "AND password=@password";
- cmd.Parameters.Add("@username", System.Data.Odbc.OdbcType.VarChar, 64).Value = Username.Value;
- cmd.Parameters.Add("@password", System.Data.Odbc.OdbcType.VarChar, 128).Value = FormsAuthentication.HashPasswordForStoringInConfigFile(Password.Value, "md5"); // Or "sha1"
- MyConnection.Open();
- OdbcDataReader Reader = cmd.ExecuteReader();
- if (Reader.Read())
复制代码
在上一点的。
[ 本帖最后由 红发 于 16-3-2006 09:13 AM 编辑 ] |
|
|
|
|
|
|
|
发表于 16-3-2006 10:48 AM
|
显示全部楼层
你的 cmd 完全没有和 MyConnection 有联系呀.
在这之前: MyConnection.Open();
应该先放 cmd.Connection = MyConnection; |
|
|
|
|
|
|
|

楼主 |
发表于 16-3-2006 01:05 PM
|
显示全部楼层
好的谢谢goatstudio大大。
回家test看。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|