PDA

View Full Version : سوال: ضرورت detach



nazihosseinioun
چهارشنبه 01 مرداد 1393, 13:24 عصر
اگر از

objConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + @"\databasename.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
استفاده كنم اتصال به بانك جواب نميده و حتما بايد User Instance=false
باشد
حالا اگر در حالت User Instance=false ارتباط گرفتم بايد در انتهاي برنامه بانك را detach كنم؟
چون در غير اينصورت در اجراي بعدي پيام ميده كه db قبلا attach شده است!

محمد آشتیانی
چهارشنبه 01 مرداد 1393, 15:46 عصر
سلام
کانکشن استرینگت رو با فرمتی که تو پست شماه 8 این تاپیک اومده بنویس ، باید مشکلت حل بشه
http://barnamenevis.org/showthread.php?457751-%D9%86%D8%AD%D9%88%D9%87-%D8%AD%D9%84-%DA%A9%D8%B1%D8%AF%D9%86-%D9%85%D8%B4%DA%A9%D9%84-%D8%A7%D8%AA%D8%B5%D8%A7%D9%84-%D8%A8%D9%87-sql-%D8%AF%D8%B1-C



موفق باشید.

nazihosseinioun
دوشنبه 13 مرداد 1393, 12:39 عصر
چرا در 2010 از setting كه connectionstring را ست ميكنم جواب ميده ولي از داخل برنامه كه اجرا ميكنم باز هم همون پيغام را ميده.
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\ab.mdf; Integerated Security=true;connect timeout=30;User Instance=False
لطفا راهنمايي كنيد
ضمنا امكان Database=ab را نميتونم اضافه كنم چون پيغام ميده كه app.config با setting متفاوت است!

nazihosseinioun
سه شنبه 14 مرداد 1393, 10:32 صبح
مرسي از راهنمايي تونالبته بعلاوه يكمقدار جستجو در حد ده روز در اينترنت من را به جواب رسوند. جهت اطلاع بقيه دوستان ماحصل آن را براتون مي گذارم:The database name must be specified with the keyword 'database' (or one of its aliases) as in the following:"AttachDbFileName=|DataDirectory|\data\YourDB.mdf;i ntegrated security=true;database=YourDatabase"An error will be generated if a log file exists in the same directory as the data file and the 'database' keyword is used when attaching the primary data file. In this case, remove the log file. Once the database is attached, a new log file will be automatically generated based on the physical path.2-First, change the default account to LocalSystem in SQL Server Connection Manager. The default Local Service account is used when SQL Server Express is installed.Because the Local Service account doesn’t have permissions to access the database residing under the My Document folder, you’ll like to see an error below: A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.The second issue has something to do with the user instance. If you are not logged in as a local administrator, you need to change the User Instance to “False”. You can either modify the connection string directly or right click the database in Server Explorer, select Modify Connection to open the connection dialog box, click Advanced and find the Use Instance property at the bottom of the Advanced Properties dialog box and change it to “False”. With the change, the connection uses the LocalSystem account instead of your current user account, which may not have access rights to the local database. Problem solved!3-Deleting the folder C:\Users\User\AppData\Local\Microsoft\Microsoft SQL Server Data worked for me in Windows 7.