这个程序怎么老是出现这样的错误:
“创建调试信息文件“D:\第5章 数据库应用\案例6:在SQL Server中存储显示图片\DisplayImagesApp\obj\Debug\DisplayImages.PDB”时发生意外的错误 --“D:\第5章 数据库应用\案例6:在SQL Server中存储显示图片\DisplayImagesApp\obj\Debug\DisplayImages.pdb: 拒绝访问。
”
不知道怎么回事??
getdata.cs这个代码文件是这样的:
[CODE]using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
namespace photo
{
public class image_query
{
string image_filename = null;
byte[] image_bytes = null;
SqlConnection image_connection = null;
SqlCommand image_command = null;
SqlDataReader image_reader = null;
public image_query()
{
image_connection = new SqlConnection(
@"Data Source=(local);" +
"Integrated Security=SSPI;" +
"Initial Catalog=EAlbum;" +
"Connect Timeout=3");
image_command = new SqlCommand(
@"SELECT name, photo FROM Photos",
image_connection);
// Open the connection and read data into the DataReader.
image_connection.Open();
image_reader = image_command.ExecuteReader();
}
public Bitmap get_image()
{
MemoryStream ms = new MemoryStream(image_bytes);
Bitmap bmap = new Bitmap(ms);
return bmap;
}
public string get_filename()
{
return image_filename;
}
public bool get_row()
{
//如果还可以读取 则读取该行
if (image_reader.Read())
{
image_filename = (string) image_reader.GetValue(0);
image_bytes = (byte[]) image_reader.GetValue(1);
return true;
}
else
{
return false;
}
}
public void end_query()
{
// Close the reader and the connection.
image_reader.Close();
image_connection.Close();
}
}
}[/CODE]
Model.cs代码文件是:
[CODE]using System;
using System.Drawing;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace photo
{
//模型类
public class Model
{
//定义了一系列的列表,用于存储从数据库中取出的数据
public ArrayList idList,categoryList,nameList,descList,searchMark,albumList,timeList,observer;
private SqlConnection sqlConn;
//图片类型
public Image image;
//标识结点位置
public int ListIndex;
//析构函数,用于关闭与数据库的连接
~Model()
{
if(sqlConn.State == ConnectionState.Open)
sqlConn.Close();
}
//构造函数,初始化、实例化Model类中的成员变量
public Model()
{
sqlConn=new SqlConnection("data source=Localhost;initial catalog=EAlbum;User ID=sa;Password=sa;");
//连接数据库
if(sqlConn.State == ConnectionState.Closed)
sqlConn.Open();
}
//添加照片,参数file为文件名,cateid为照片属于的种类
public void addphoto2(string file)
{
//将文件名为file的文件读入到buffer中
System.IO.FileStream stream = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, (int)stream.Length);
stream.Close();
string strName = System.IO.Path.GetFileNameWithoutExtension(file);
//调用sp_InsertPhoto存储过程,添加照片
SqlCommand cmd = new SqlCommand("sp_InsertPhoto2", sqlConn);
cmd.CommandType = CommandType.StoredProcedure;
//SqlParameter param = cmd.Parameters.Add("RETURN_VALUE", SqlDbType.Int);
//param.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = strName;
cmd.Parameters.Add("@image", SqlDbType.Image).Value = buffer;
//cmd.Parameters.Add("@album", SqlDbType.Int).Value = cateid;
cmd.ExecuteNonQuery();
}
}
}[/CODE]
photo.cs这个窗体代码是:
[CODE]using System;
using System.Drawing;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace photo
{
//模型类
public class Model
{
//定义了一系列的列表,用于存储从数据库中取出的数据
public ArrayList idList,categoryList,nameList,descList,searchMark,albumList,timeList,observer;
private SqlConnection sqlConn;
//图片类型
public Image image;
//标识结点位置
public int ListIndex;
//析构函数,用于关闭与数据库的连接
~Model()
{
if(sqlConn.State == ConnectionState.Open)
sqlConn.Close();
}
//构造函数,初始化、实例化Model类中的成员变量
public Model()
{
sqlConn=new SqlConnection("data source=Localhost;initial catalog=EAlbum;User ID=sa;Password=sa;");
//连接数据库
if(sqlConn.State == ConnectionState.Closed)
sqlConn.Open();
}
//添加照片,参数file为文件名,cateid为照片属于的种类
public void addphoto2(string file)
{
//将文件名为file的文件读入到buffer中
System.IO.FileStream stream = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, (int)stream.Length);
stream.Close();
string strName = System.IO.Path.GetFileNameWithoutExtension(file);
//调用sp_InsertPhoto存储过程,添加照片
SqlCommand cmd = new SqlCommand("sp_InsertPhoto2", sqlConn);
cmd.CommandType = CommandType.StoredProcedure;
//SqlParameter param = cmd.Parameters.Add("RETURN_VALUE", SqlDbType.Int);
//param.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = strName;
cmd.Parameters.Add("@image", SqlDbType.Image).Value = buffer;
//cmd.Parameters.Add("@album", SqlDbType.Int).Value = cateid;
cmd.ExecuteNonQuery();
}
}
}[/CODE]