您好,请使用此连接字符串帮助我,甚至附加我的过程属性
try
{
conn = new SqlConnection("Server=RM-MOBL\MSSQLSERVER1;DataBase=master;Trusted_Connection=True;");
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.new", conn);
cmd.CommandType = CommandType.StoredProcedure;
rdr = cmd.ExecuteReader();
Console.WriteLine(" connection success");
}
// I hope I have mentioned correct connection string but
// not able to execute my stored procedure
我面临错误
![请在这里查看错误] [3]
上面的代码可能不是连接数据库的最佳方法。
在您的web.config中添加以下行,这些行将连接到您的数据库<configuration>
部分:
<connectionStrings >
<add name="myConnectionString" connectionString="Server=ServerName;Database=DatabaseName;User ID=UserId;Password=Password;Trusted_Connection=False;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
并在您的C#文件中添加这些引用
using System.Data.SqlClient;
using System.Web.Configuration;
在公共类内添加此连接
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);
现在,您可以通过以下方式打开连接 con.Open();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句