0 Replies - 645 Views - Last Post: 17 February 2009 - 01:09 PM Rate Topic: -----

#1 Kkarinisme  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 07-February 09

Sql Connection problem

Post icon  Posted 17 February 2009 - 01:09 PM

I have set up a form to attempt to connect to an sql server to create the database, My Stickies. I used code I found on the net to run when the form loads. I do include using System.Data.Sqlclient and System.Configuration. I have created the folder in which to place the mdf and ldf files on the C: drive in the root directory.

I get the following exception when I run the form:
System.Data.SqlClient.SqlException: a network related or instance-specific error occurred while establishing a connection to Sql Server. Listed as error 40.

I have enabled everything on the SqlManager. It does show the Sql Server (SQLExpress) as running and the browser and agent as stopped.

I am stumped. Thx for any help. Karin


	 private void FrmCreateDatabase_Load(object sender, EventArgs e)
		{
			String str;
			SqlConnection myConn = new SqlConnection("Server=local;Integrated security=SSPI;database=master");

			str = "CREATE DATABASE MyStickies ON PRIMARY " +
				"(NAME = MyStickies_Data, " +
				"FILENAME = 'C:/MyStickies/MyStickies.mdf', " +
				"SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
				"LOG ON (NAME = MyStickies_Log, " +
				"FILENAME = 'C:/MyStickies/MyStickiesLog.ldf', " +
				"SIZE = 1MB, " +
				"MAXSIZE = 5MB, " +
				"FILEGROWTH = 10%)";

			SqlCommand myCommand = new SqlCommand(str, myConn);
			try
			{
				myConn.Open();
				myCommand.ExecuteNonQuery();
				MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
			catch (System.Exception ex)
			{
				MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
			finally
			{
				if (myConn.State == ConnectionState.Open)
				{
					myConn.Close();
				}
			}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1