c#.net连接sqlserver数据库出现了问题

gasmade 2005-01-24 06:47:21
我想做个web页,能提交数据之类的。这是我的这个aspx文件的内容:
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>
<script language="c#" runat="server">
string strConnection="server=localhost;uid=sa;pwd=111;database=mytest";
SqlConnection sqlcon=new SqlConnection(strConnection);
sqlcon.Open();
</script>

<html>
...
...全文
266 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
marvelstack 2005-01-29
  • 打赏
  • 举报
回复
http://dev.csdn.net/article/16/16437.shtm
http://www.connectionstrings.com/
http://community.csdn.net/Expert/TopicView3.asp?id=3705163
yang20052008 2005-01-28
  • 打赏
  • 举报
回复
string strConnection= "data source=localhost;initial catalog=mytest;user id=sa;Password=111;";
SqlConnection sqlcon=new SqlConnection(strConnection);
sqlcon.Open();
skyeenet 2005-01-28
  • 打赏
  • 举报
回复
string strConnection="server='(local)';uid=sa;pwd=111;database=mytest";

保证是这个
jiaoyonggang 2005-01-28
  • 打赏
  • 举报
回复
同意 gabriel1(星空微凉,泪眼汪汪,思念今日更长)
顶!!!!!!!!!!!!!!!!!!!!!!!
karykwan 2005-01-28
  • 打赏
  • 举报
回复
用代码后置写啊.方便点.至少不会有的方法写错..
心情解码 2005-01-28
  • 打赏
  • 举报
回复
:)




---
dazhu2 2005-01-28
  • 打赏
  • 举报
回复
你用服务器管理器连接数据库看看
luoyuechen 2005-01-28
  • 打赏
  • 举报
回复
用c#自带的连接数据库 连连看
zr1982930 2005-01-28
  • 打赏
  • 举报
回复
.NET有时是很奇怪的出现一些问题我也遇到过,大概是没装好吧!重装以后就一切OK了!
gasmade 2005-01-27
  • 打赏
  • 举报
回复
算了,偶也不知道原因

但偶装了.net后就可以了。。。。。

wingnal 2005-01-26
  • 打赏
  • 举报
回复
strConnection="server=(local);uid=sa;pwd=111;database=mytest";
SqlConnection sqlcon=new SqlConnection(strConnection);
yanyzty 2005-01-26
  • 打赏
  • 举报
回复
主要还是连接字符串没有打开
SqlConnection sqlcon=new SqlConnection(strConnection);
fellowcheng 2005-01-26
  • 打赏
  • 举报
回复
也就是把连接代码放入Page_Load()事件中 *_*
fellowcheng 2005-01-26
  • 打赏
  • 举报
回复
把连接数据库代码改为
public void Page_Load()
{
string strConnection="server=localhost;uid=sa;pwd=111;database=mytest";
SqlConnection sqlcon=new SqlConnection(strConnection);
sqlcon.Open();
}
fellowcheng 2005-01-26
  • 打赏
  • 举报
回复
看看
winxieddd 2005-01-26
  • 打赏
  • 举报
回复
双击SqlConnection用属性设计器里的ConnectionString属性生成一个,确保可以连接上了,然后把字符串copy到那句上去。
gabriel1 2005-01-26
  • 打赏
  • 举报
回复
可能有多中问题造成..
1.用户/密码是否正确?
2.数据库验证模式是否已经是混合验证?
3.数据库系统是否正常?
gasmade 2005-01-26
  • 打赏
  • 举报
回复
还是不行
smallMage 2005-01-24
  • 打赏
  • 举报
回复
string strConnection="server=localhost;uid=sa;pwd=111;database=mytest";
改为:
string strConnection="server=local;uid=sa;pwd=111;database=mytest";

gasmade 2005-01-24
  • 打赏
  • 举报
回复
出错如下:
Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1519: Invalid token '(' in class, struct, or interface member declaration

Source Error:



Line 4: string strConnection="server=localhost;uid=sa;pwd=111;database=mytest";
Line 5: SqlConnection sqlcon=new SqlConnection(strConnection);
Line 6: sqlcon.Open();
Line 7: </script>
Line 8: <style Type="Text/css">


Source File: c:\inetpub\wwwroot\lyl\test.aspx Line: 6

110,568

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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