2 Replies - 40860 Views - Last Post: 25 February 2010 - 10:41 AM Rate Topic: -----

#1 getajob1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 03-February 09

Connecting to Sql Server 2008 Sample Database

Posted 20 February 2009 - 03:12 PM


I am having trouble connecting to the AdventureWorks_Data.mdf. I can connect to a report server temp db but there is no data in it.
Using the same code to connect to AdventureWorks_Data.mdf gives an error "network related or instance specific error occurred
while connecting to SQL Server". I don't get it as the temp db connect works (see // above actual ran code). Help Please!

 public void LoadSql()
		{

		   // string connectionString = @"Provider=System.Data.SqlClient;
		   //							 Persist Security Info=False;
		   //							 Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS2\MSSQL\DATA\ReportServer$SQLEXPRESS2TempDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;
		   //							 Integrated Security=SSPI;
		   //							 Trusted_Connection=TRUE;
		   //							 Application Name=SampleCSharpApplication";
		  //  string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS2\MSSQL\DATA\ReportServer$SQLEXPRESS2TempDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";   
			string connectionString =   @"Data Source=Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS2\MSSQL\DATA\AdventureWorks_Data.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";							 
																			  
			string sqlSel = @"Select * From Address";	 

			SqlConnection conndb = new SqlConnection(connectionString); //make a OleDbConnection object					  
			DataSet ds = new DataSet();								 //make a DataSet object
			
			try
			{				
				SqlDataAdapter myAdapter = new SqlDataAdapter(sqlSel, conndb); //Using the OleDbDataAdapter execute the query				
				myAdapter.Fill(ds, "Address");							   //Fill the DataSet with the Table 'Customers'
				gridColors.DataSource = ds.Tables["Address"];				
				myAdapter.Dispose();
			}
			catch (Exception e)
			{
				MessageBox.Show("Error in connecting! " + e.ToString(), "Error");
			}
			finally
			{				
			   conndb.Close();	 //Close the OleDbConnection
			   conndb.Dispose();
			}
		}


This post has been edited by getajob1: 20 February 2009 - 03:37 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Connecting to Sql Server 2008 Sample Database

#2 getajob1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 03-February 09

Re: Connecting to Sql Server 2008 Sample Database

Posted 21 February 2009 - 08:22 AM


Found my answer my searching other peoples questions. I just had to tell it what server and attach a db file name. Thanks to all you answer people!!

string connectionString = @"server = ABM\SQLEXPRESS;integrated security = true;User Instance=True;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS2\MSSQL\DATA\AdventureWorksDW_Data.mdf";


This post has been edited by getajob1: 21 February 2009 - 08:23 AM

Was This Post Helpful? 0
  • +
  • -

#3 Guest_benjamin*


Reputation:

Re: Connecting to Sql Server 2008 Sample Database

Posted 25 February 2010 - 10:41 AM

that for the post ! this helped me alot !
Was This Post Helpful? 0

Page 1 of 1