Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Problem with Sql Server 2008 need help (!!!)

Author  Topic 

West
Starting Member

2 Posts

Posted - 2010-08-21 : 07:30:31
well I am using simple winforms which stores image into database
here is fragment of this code

private void btn_Save_Click(object sender, EventArgs e)
{
byte[] imagedata = ReadFile(txtImageLoc.Text);

SqlConnection connection = new SqlConnection("Data Source=WEST/SQLEXPRESS; Initial Catalog=Images; Integrated Security=true;");

string query = "insert into ImagesStore (ImageData)values(@ImageData)";

SqlCommand command = new SqlCommand(query, connection);
command.Parameters.Add(new SqlParameter("@ImageData", (object)imagedata));

connection.Open(); here throws this exception *
command.ExecuteNonQuery();
connection.Close();
this.Close();
}


* - 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)

I have not idea what is problem, help :(

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-21 : 13:21:24
have you enabled remote connection in sql server configuration manager?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

West
Starting Member

2 Posts

Posted - 2010-08-22 : 03:58:17
quote:
Originally posted by visakh16

have you enabled remote connection in sql server configuration manager?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




I solve it... problem was simple

"Data Source=WEST/SQLEXPRESS; Initial Catalog=Images; Integrated Security=true;"


instead of this I should write like this

@"Data Source=WEST/SQLEXPRESS; Initial Catalog=Images; Integrated Security=true;"


I faced first time such a problem

and this @, what does it do?
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-08-22 : 09:15:35
It indicated to .Net that the following string needs to be taken as a literal and any escape characters ignored. Without the @, you need to escape the \, typically like so:

"Data Source=WEST\\SQLEXPRESS; Initial Catalog=Images; Integrated Security=true;"

--
Gail Shaw
SQL Server MVP
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-22 : 11:10:12
I thought you needed to use Backslash "\" character? Not division "/"...




N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-08-22 : 12:29:28
Yeah, you're right. Might have been a typo from the OP. I'll edit mine to fix.

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -