A problem for ODBC.net, who could help me?

duanzj 2002-10-11 06:22:37
I'm trying to do simple connection with my database using ODBC.NET.
For that, I have created a very simple ASP.NET application under
Visual Studio.NET and I have placed the following code under a
button's onclick event.
---------
OdbcConnection cn;
OdbcCommand cmd;
string MyString;
MyString="Select * from table_name";
cn= new OdbcConnection("dsn=DSN_Name;UID=dba;PWD=sql;");
cmd=new OdbcCommand(MyString,cn);
try
{
cn.Open();
EnvMessage.Text = "Connected..";
}
catch(Exception ex)
{
EnvMessage.Text = "Failied. " + ex.ToString();
}
cn.Close();
-----------

table_name - I'm using a valid database table name.
DSN_Name - I'm using a valid DSN name that I have been using for my
windows application.

I'm getting the following errror.
------
Microsoft.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC
Driver Manager]
Data source name not found and no default driver specified at
Microsoft.Data.Odbc.OdbcConnection.Open()
at DSCOdbcConnection.WebForm1.Connect_Click(Object sender, EventArgs
e)
in c:\inetpub\wwwroot\dscodbcconnection\webform1.aspx.cs:line 96
------

If I create a Windows application instead of ASP.NET application, it
works just fine. It's connected with database. But ASP.NET application
throws the above error message.

Any help? I appreciate your help.

I'm here using DSN method to connect. Please help with correct
connection string.

...全文
39 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

1,978

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧