PDA

View Full Version : DB



ara12345
شنبه 03 شهریور 1386, 12:02 عصر
سلام
لطفا" بمن بگید Error برنامه من برای چیه؟

Format of the initialization string does not conform to specification starting at index 44


برنامه من:


publicpartialclassfrmparchehenter : Form

{
string strConn = "server=localhost;Data Source=\".\\SQLEXPRESS\";AttachDbFilename=\"C:\\Documents and Settings\\neda\\My Documents\\Visual Studio 2005\\Projects\\WindowsApplication1\\WindowsApplic ation1\\factory.mdf;Integrated Security=True;User Instance=True;database= factory";

SqlConnection scnn;
SqlDataAdapter sdacloths;
DataSet dscloths;

public frmparchehenter()
{
InitializeComponent();
this.scnn = newSqlConnection(strConn);
this.sdacloths = newSqlDataAdapter("Select * from Datagrid", scnn);
this.dscloths = newDataSet();
sdacloths.Fill(dscloths, "DataGrid");
dataGridView1.DataSource = dscloths;
dataGridView1.DataMember = "DataGrid";


}


(privatevoid BtnSave_Click(object sender, EventArgs e)

SqlConnection scnn = newSqlConnection(strConn);
SqlCommand scmdCloths = newSqlCommand();
scmdCloths.CommandText = " INSERT INTO Clothss " + "(Name , Family , DAte, weight,Number)" + " VALUES (@StrName ,@StrFamily , @StrDate ,@StrWeight ,@StrNumber)";
scmdCloths.Parameters.AddWithValue("@StrFamily",TxtFamily.Text);
scmdCloths.Parameters.AddWithValue("@StrDate",TxtDate.Text);
scmdCloths.Parameters.AddWithValue("@StrWeight",TxtWeight.Text);
scmdCloths.Parameters.AddWithValue("@StrNumber",TxtNumber.Text);
scnn.Open();
// scnn.strConn();

scmdCloths.ExecuteNonQuery();

{

mehdi.mousavi
شنبه 03 شهریور 1386, 14:12 عصر
سلام
لطفا" بمن بگید Error برنامه من برای چیه؟

Format of the initialization string does not conform to specification starting at index 44


[/FONT]


سلام.
لطفا به این سایت رجوع کنید. (http://support.microsoft.com/kb/823679/)

ara12345
شنبه 03 شهریور 1386, 14:56 عصر
یعنی من باید TimeOut بذارم؟

hdv212
شنبه 03 شهریور 1386, 15:40 عصر
ConnectionString تون رو خیلی پیچیده نوشتید، به خاطر همین هم دچار اشتباه و اشکال شدید، سعی کنید از این نمونه الگو برداری کنید :

Server=.\SQLExpress;AttachDbFilename=|DataDirector y|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
اینم سایتش :
http://www.connectionstrings.com/?carrier=sqlserver2005

mehdi.mousavi
شنبه 03 شهریور 1386, 15:59 عصر
یعنی من باید TimeOut بذارم؟


خیر! به Timeout چه ربطی داره. لینکی رو که دادم اگر با دقت بخونید، میبینید که:



Version 1.1 of SqlClient introduced a regression in the handling of connection strings that contain apostrophes (') or double quotation marks (""). This causes connection strings with correctly escaped apostrophes or double quotation marks to fail, and you receive the following error message:
Format of the initialization string does not conform to specification starting at index {0}.
This fix removes this regression.


اگر از نسخه ای 1.1 dotNet Framework استفاده می کنید، Hot Fix داده شده مشکل رو از بین میبره. اگر از نسخه های بعدی استفاده می کنید، باید Connection String رو بدقت بررسی کنید. برای ساختن Connection String و اینکه دچار اشتباه نشید، یه فایل .txt رو Desktop بسازید، سپس اونو به .udl تغییر نام بدید. بعد دو بار روش Click کنید تا Data Link Properties باز بشه. اونوقت Connection String رو بصورت Visual بسازید، Test کنید و نتیجه رو ذخیره کنید. در نهایت فایل .udl رو درون Notepad باز کنید و Connection String رو تو برنامه خودتون کپی کنید.