PDA

View Full Version : Connection String برای دیتابیسی که تو به برنامه Add میشه



pishraft
یک شنبه 22 اسفند 1389, 08:29 صبح
سلام
خوبین؟

برا دیتابیسی که به برنامه با Add Existing اضافه کردم چطور باید Connection String بنویسم؟
دیتابیس من SQL Server هست
مرسی

morteza271
یک شنبه 22 اسفند 1389, 09:21 صبح
فکر کنم این براتون مناسب باشه :

Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\my dbfile.mdf;Database=dbname; Trusted_Connection=Yes;


اگر این خوب نبود لیست انواع ConnectionString رو میتونی تو لینک زیر ببینی :
http://www.connectionstrings.com/sql-server-2008

موفق باشید

pishraft
یک شنبه 22 اسفند 1389, 12:12 عصر
نشد :گریه:
با هیچکدوم کار نکرد
میشه یه نمونه کد بزارین که Db هم بهش Add شده باشه؟ فقط یه Select رو هم جواب بده کافیه برام
مرسی، خیلی مهمه برام

morteza271
یک شنبه 22 اسفند 1389, 14:50 عصر
نمونه برنامه ندارم.
چه خطایی میده؟
خطاشو بذارید.

pishraft
یک شنبه 22 اسفند 1389, 15:13 عصر
A network-related or instance-specific error occurred while establishing a connection to SQL Server.
The server was not found or was not accessible.
Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

این خطا رو میده

morteza271
یک شنبه 22 اسفند 1389, 15:28 عصر
فکر کنم اInstanci که گذاشتین اشتباه در اینجا :

Server=.\SQLExpress;
میشه ConnectionString ی رو که استفاده کردین رو بذارین اینجا.

pishraft
یک شنبه 22 اسفند 1389, 15:40 عصر
"Server=./SQLExpress;AttachDbFilename=C:\\Users\\Pishraft\\D ocuments\\Visual Studio 2008\\Projects\\NameCh\\NameCh\\bin\\Release\\Nch. mdf;Database=Nch.mdf; Trusted_Connection=Yes;"

morteza271
یک شنبه 22 اسفند 1389, 15:55 عصر
ازین استفاده کنین بینین نمیشه :

SqlConnection con = new SqlConnection("data source=.\\sqlexpress;attachdbfilename=|datadirecto ry|\\db.mdf;integrated security=true; user instance=true");



فقط به جای db.mdf اسم دیتابیس خودتون رو بذارین.