用Visual Studio 2011写登陆实例的时候出现错误
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSy...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string dataDir = AppDomain.CurrentDomain.BaseDirectory;
if (dataDir.EndsWith(@"\bin\Debug\")
|| dataDir.EndsWith(@"\bin\Release"))
{
dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
}
using (SqlConnection conn = new SqlConnection(@"Data Source=.\;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=False"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "Insert into MyDB(Name) values('abc')";
cmd.ExecuteNonQuery();
Console.WriteLine("插入成功");
}
}
Console.WriteLine("数据库连接成功");
Console.ReadLine();
}
}
}
User Instance=True的时候提示此版本的 SQL Server 不支持用户实例登录标志。该连接将关闭
改了成User Instance=False的后不弹出这个
但是输入数据的时候提示如图所示
该怎么解决呢? 展开
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string dataDir = AppDomain.CurrentDomain.BaseDirectory;
if (dataDir.EndsWith(@"\bin\Debug\")
|| dataDir.EndsWith(@"\bin\Release"))
{
dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
}
using (SqlConnection conn = new SqlConnection(@"Data Source=.\;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=False"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "Insert into MyDB(Name) values('abc')";
cmd.ExecuteNonQuery();
Console.WriteLine("插入成功");
}
}
Console.WriteLine("数据库连接成功");
Console.ReadLine();
}
}
}
User Instance=True的时候提示此版本的 SQL Server 不支持用户实例登录标志。该连接将关闭
改了成User Instance=False的后不弹出这个
但是输入数据的时候提示如图所示
该怎么解决呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询