error in loading dll

Joined
Jan 17, 2012
Messages
1
Reaction score
0
Hi,
I have windows 7, Microsoft Access 2010. I created a dll using Microsoft Visual Studio 2010, C#, with a class. When I open MS Access and select Tools>References and then click on my dll, I get "error in loading dll" this is my code:

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using System.Data.SqlClient;
namespace GEOINT_REPOSITORY
{
public class GEOINT_REPOSITORY
{
public static string strPet_Name = "";
public static string strPhoto_Location = "";
static void Main(string[] args)
{
if (args == null || args.Length == 0 || args.Length > 3)
{
Console.WriteLine("PetPhotoManager examples:\n\n");
Console.WriteLine("PetPhotoManager /upload [pet_name] [photo_location]\n");
Console.WriteLine("PetPhotoManager /view [pet_name]\n");
return;
}
strPet_Name = args[1].ToString();
if (args[0] == "/upload")
{
strPhoto_Location = args[2].ToString();
UploadPhoto();
return;
}
else if (args[0] == "/View")
{
// ViewPhoto();
}
}
private static void UploadPhoto()
{
try
{
//Open a connection to the OnlinePetStore database
string strCommand = "";
SqlConnection con = new SqlConnection(@"server=JITC-PC\GEOINT;database=OnlinePetStore;integrated security=SSPI");

con.Open();
//We need to creat a GUID that will be used
//as a unique identifier for the row
Guid NewGuid = Guid.NewGuid();
//Create an entry in the table for our new pet
strCommand = "INSERT INTO Pets VALUES(CAST('"+ NewGuid + "' AS UNIQUEIDENTIFIER),'" + strPet_Name + "',0)";
SqlCommand MySQLCommand = new SqlCommand(strCommand, con);
MySQLCommand.ExecuteNonQuery();
//Now query to get the filestream fileshare and transaction context
strCommand = "SELECT pet_photo.PathName()," + "GET_FILESTREAM_TRANSACTION_CONTEXT() FROM Pets " +
"WHERE FSRowGuidColumn=CAST('" + NewGuid + "' AS UNIQUEIDENTIFIER)";
SqlTransaction SQLTrans = con.BeginTransaction();
MySQLCommand.CommandText = strCommand;
MySQLCommand.Transaction = SQLTrans;
SqlDataReader rdr = MySQLCommand.ExecuteReader();
if (rdr.Read())
{
//Variables for the filestream path, transaction context and length
string path = (string)rdr[0];
byte[] txtContext = (byte[])rdr[1];
int length = txtContext.Length;
//Close the data reader prior to calling OpenSqlFilestream
rdr.Close();
SafeFileHandle handle = OpenSqlFilestream(
(string)path,
1, // 1=Write access
0,
txtContext,
(UInt32)length,
new LARGE_INTEGER_SQL(0));
//Destination
FileStream writeBlob = new FileStream(handle, FileAccess.Write);
//Source
FileStream readPhoto = new FileStream(strPhoto_Location,
FileMode.Open, FileAccess.Read);
//Define block size, 512K is what NTFS is.
const int blockSize = 1024 * 512;
//Stream bytes from a local file into a sql table via FileStream!
byte[] buffer = new byte[blockSize];
int bytesRead;
while ((bytesRead = readPhoto.Read(buffer, 0, buffer.Length)) > 0)
{
writeBlob.Write(buffer, 0, bytesRead);
}
writeBlob.Close();
readPhoto.Close();
SQLTrans.Commit();
Console.WriteLine("\n" + strPhoto_Location + " inserted into Pets table.\n");
}
con.Close();
}
catch (Exception E)
{
Console.WriteLine("Error: " + E.Message.ToString());
}
return;
}
[DllImport("sqlncli10.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern SafeFileHandle OpenSqlFilestream(
string FilestreamPath,
UInt32 DesiredAccess,
UInt32 OpenOptions,
byte[] FileStreamTransactionContext,
UInt32 FileStreamTransactionContextLength,
LARGE_INTEGER_SQL AllocationSize);
[StructLayout(LayoutKind.Sequential)]
public struct LARGE_INTEGER_SQL
{
public Int64 QuadPart;
public LARGE_INTEGER_SQL(Int64 quadPart) { QuadPart = quadPart; }
}
}
}

I have checked many, many forums but haven't found the answer. I have a new machine with the latest version of mdac.

Thanks,
Sharon:(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top