الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكلة في امر Configurationmanager.connectionstrings

بدأه ابو عبدالله2 في 7 يناير 2009 · 2 رد · 764 مشاهدة · في ADO.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكــم ورحمـة الله وبركاتــه

لدي مشكلة في امر الاتصال بقاعدة بيانات Sql server التالي:

string connectionString = ConfigurationManager.ConnectionStrings[ "DatabaseName"].ConnectionString.toString();

حيث تظهر لي الرسالة التالية:

Object reference not set to instance of object

الرجاء المساعدة في حل هذه المشكلة

تم تعديل هذه المشاركة بواسطة ابو عبدالله2 في 7 يناير 2009 في 20:58

#2

و عليكم السلام و رحمة الله و بركاته

اهلاً بك اخي

انا مني فاهم قصدك بالضبط و هذا كود الربط مع قاعدة و سيرفر

v
/*
  FirstExample.cs illustrates how to:
  1. Connect to the SQL Server Northwind database.
  2. Retrieve a row from the Customers table using
	 a SQL SELECT statement.
  3. Display the columns from the row.
  4. Close the database connection.
*/

using System;
using System.Data.SqlClient;

class FirstExample
{
  public static void Main()
  {
	try
	{
	  // step 1: create a SqlConnection object to connect to the
	  // SQL Server Northwind database
	  SqlConnection mySqlConnection =
		new SqlConnection(
		  "server=localhost;database=Northwind;uid=sa;pwd=sa"
		);

	  // step 2: create a SqlCommand object
	  SqlCommand mySqlCommand = mySqlConnection.CreateCommand();

	  // step 3: set the CommandText property of the SqlCommand object to
	  // a SQL SELECT statement that retrieves a row from the Customers table
	  mySqlCommand.CommandText =
		"SELECT CustomerID, CompanyName, ContactName, Address "+
		"FROM Customers "+
		"WHERE CustomerID = 'ALFKI'";

	  // step 4: open the database connection using the
	  // Open() method of the SqlConnection object
	  mySqlConnection.Open();
	  // step 5: create a SqlDataReader object and call the ExecuteReader()
	  // method of the SqlCommand object to run the SELECT statement
	  SqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();

	  // step 6: read the row from the SqlDataReader object using
	  // the Read() method
	  mySqlDataReader.Read();

	  // step 7: display the column values
	  Console.WriteLine("mySqlDataReader[\" CustomerID\"] = "+
		mySqlDataReader["CustomerID"]);
	  Console.WriteLine("mySqlDataReader[\" CompanyName\"] = "+
		mySqlDataReader["CompanyName"]);
	  Console.WriteLine("mySqlDataReader[\" ContactName\"] = "+
		mySqlDataReader["ContactName"]);
	  Console.WriteLine("mySqlDataReader[\" Address\"] = "+
		mySqlDataReader["Address"]);

	  // step 8: close the SqlDataReader object using the Close() method
	  mySqlDataReader.Close();

	  // step 9: close the SqlConnection object using the Close() method
	  mySqlConnection.Close();
	}
	catch (SqlException e)
	{
	  Console.WriteLine("A SqlException was thrown");
	  Console.WriteLine("Number = "+ e.Number);
	  Console.WriteLine("Message = "+ e.Message);
	  Console.WriteLine("StackTrace:\n" + e.StackTrace);
	}
  }
}

v

Mail : pc-moon@hotmail.com

من تواضع لله رفعه

قل خيرا أو اصمت

#3

شكراً جزاك الله خير

مواضيع مشابهة