无法打开sql server连接

编程入门 行业动态 更新时间:2024-10-28 04:27:48
本文介绍了无法打开sql server连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在这个Web应用程序中开发了一个Web应用程序有8个文本框 我也有sql server2005我创建了一个数据库我写了 代码日期库连接和应用程序运行时间sqlserver 数据库没有连接如何解决但没有给出任何错误我被复制 代码

i am develop one web application in this web application has 8 textboxes and also i have the sql server2005 i created the one database i write the code date base connection and application is running time the sqlserver database not connected how to solve but not given the any error i am copied code

protected void Button1_Click(object sender, EventArgs e) { SqlConnection connect=new SqlConnection("Data Source=ADMIN-E41B7B0DB\\SQLEXPRESS;Initial Catalog=agfl;connect timeout=30;Integrated Security=True"); SqlCommand mycommand; mycommand= new SqlCommand("Insert into pac(sno,rdate,acno,name,vno,amt,chno,edate) values('"+TextBox1.Text+"','"+TextBox5.Text+"','"+TextBox2.Text+"','"+TextBox6.Text+"','"+TextBox3.Text+"','"+TextBox7.Text+"','"+TextBox4.Text+"','"+TextBox8.Text+"')", connect ); connect.Open(); mycommand.Parameters.AddWithValue("rdate", TextBox5.Text); mycommand.Parameters.AddWithValue("sno", TextBox1.Text); mycommand.Parameters.AddWithValue("acno", TextBox2.Text); mycommand.Parameters.AddWithValue("name", TextBox6.Text); mycommand.Parameters.AddWithValue("vno", TextBox3.Text); mycommand.Parameters.AddWithValue("amt", TextBox7.Text); mycommand.Parameters.AddWithValue("chno", TextBox4.Text); mycommand.Parameters.AddWithValue("edate", TextBox8.Text); mycommand.ExecuteNonQuery(); connect.Close(); }

推荐答案

两个原因: 1)连接已创建,但从未打开过, 2)命令已创建,但没有参数。 有你听说过 SQLInjection [ ^ ]?请阅读这些文章: 如何:在ASP中防止SQL注入。 NET [ ^ ] 在停止之前阻止SQL注入攻击 [ ^ ] 我建议你使用存储过程: 如何:致电使用ADO.NET和Visual C#.NET进行参数化存储过程 [ ^ ] 如何:执行存储返回无值的过程 [ ^ ] Two reasons: 1) connection has been created, but never opened, 2) command has been created but does not have parameters. Have you ever heard about SQLInjection[^]? Please, read these articles: How To: Protect From SQL Injection in ASP.NET[^] Stop SQL Injection Attacks Before They Stop You[^] I would suggest you to use stored procedure: HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET[^] How to: Execute a Stored Procedure that Returns No Value[^]

我想你的 ConnectionString 是错误的。 尝试使用正确的,参考 - SQL Server 2005连接字符串 [ ^ ]。 还使用参数化查询/存储过程以避免 SQLInjection 正如 Maciej Los I guess your ConnectionString is wrong. Try to use the correct one, refer - SQL Server 2005 connection strings[^]. Also use Parameterized Query/Stored Procedure in order to avoid SQLInjection as suggested by Maciej Los

所建议的那样检查sql server express的服务是否正在运行,如果没有则启动服务。 check the servive of sql server express is it running if not then start service .

更多推荐

无法打开sql server连接

本文发布于:2023-11-06 17:51:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法打开   sql   server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!