数据未插入.mdf数据库文件 [英] Data in not inserting into .mdf database file
问题描述
您好,我正在尝试将数据插入.mdf db文件,当我在连接字符串中指定完整路径时,它正在工作,但是当我使用| DataDirectory |指定路径时然后运行时显示数据已插入,但数据未插入.mdf数据库文件
我尝试过:
它正在工作
connection = new SqlConnection(@Data Source = .\SQLEXPRESS; AttachDbFilename = C:\ Users \ Kishan \Documents\\ \\ Visual Studio 2008 \Projects \Shriya Graphics \Shriya Graphics \Shriya_Graphics.mdf; Integrated Security = True; User Instance = True);
it不工作
connection = new SqlConnection(Properties.Settings.Default.ConnString);
Hello, I am Trying to insert data into .mdf db file when i am specifying the full path in connection string then it's working but when i am specifying path using |DataDirectory| then runtime it's showing data is inserted but data is not inserting into .mdf database file
What I have tried:
it's Working
connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Kishan\Documents\Visual Studio 2008\Projects\Shriya Graphics\Shriya Graphics\Shriya_Graphics.mdf;Integrated Security=True;User Instance=True");
it is not Working
connection = new SqlConnection(Properties.Settings.Default.ConnString);
推荐答案
如果顶线工作 - 和你不应该使用它,硬编码连接字符串是一个坏主意 - 第二个不是,那么你需要使用调试器,看看究竟是什么Properties.Settings.Default.ConnString
正在返回。几乎可以肯定,它不是一个有效的SQL连接字符串,或者它可以处理不同的数据库。
请记住,附加数据库只能用于开发,不能用于开发除了在SQL Server的Express版本上使用。如果您尝试在生产中使用它,它将始终失败。
If the top line is working - and you shouldn't be using that, hard-coded connections strings are a bad idea - and the second isn't, then you need to use the debugger and see exactly whatProperties.Settings.Default.ConnString
is returning. Almost certainly, it isn't a valid SQL connection string, or it addresses a different DB.
Do remember that Attaching databases is only available for development, and cannot be used except on Express editions of SQL Server. If you try to use it in production, it will always fail.
这篇关于数据未插入.mdf数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!