【发布时间】:2014-05-11 07:10:23
【问题描述】:
喂,
我在 MS Visual Studio 2012 下使用 SQL Server 2012。
下面是我来自 app.config 的连接字符串
<add key="Platform" value="Data Source=Bigfoot2;Initial Catalog=Platform;Integrated Security=True"/>
还有我的连接类
static SqlConnection con;
public static SqlConnection GetConnection()
{
con = new SqlConnection(ConfigurationManager.AppSettings["Platform"].ToString());
return con;
}
internal void AddCustomer (Buyer customer, User user, PlatformType type )
{
SqlConnection conn = DALConnection.GetConnection();
try
{
SqlCommand cmd = new SqlCommand("InsertCustomer", conn);
cmd.CommandType = CommandType.StoredProcedure;
...
con.Open();
cmd.ExecuteNonQuery();
我的数据库存储在我的项目文件夹下。
我尝试使用我的方法时遇到的错误是:
无法打开与 SQL Server 2012 的连接
此致,
【问题讨论】:
-
看来问题不在你的代码上。我建议先使用外部工具测试连接。我推荐UDL file
标签: c# sql sql-server