Showing posts with label ado. Show all posts
Showing posts with label ado. Show all posts

Friday, March 30, 2012

how can i connect to sqlserver2005 express by ado

hr = m_pConnection.CreateInstance("ADODB.Connection");
if (SUCCEEDED(hr))
{
if (FAILED(m_pConnection->Open("Provider = sqloledb;Server=(local);Database=c863;Trusted_Connection=yes","","",-1)))
{
AfxMessageBox("Can not open Database!");
m_pConnection.Release();
return FALSE;
}

}
when i debug ,there is an exception at "m_pConnection->Open("Provider = sqloledb;Server=(local);Database=c863;Trusted_Connection=yes","","",-1)))"
the exception is
'Book.exe': Loaded 'C:\Program Files\Common Files\System\Ole DB\sqloledb.rll', Binary was not built with debug information.
First-chance exception at 0x7c81eb33 in Book.exe: Microsoft C++ exception: _com_error at memory location 0x0013fba4..
how should i do?

Try

Server=(local)\SQLEXPRESS

SQL Express is installed as a "named" instance by default, an drequires the instance name specification when making a connection (as opposed to a "default" instance).|||Sorry,it dont still work.the exception is
"First-chance exception at 0x7c81eb33 in Book.exe: Microsoft C++ exception: _com_error at memory location 0x0013fba4.."|||It looks like the failure may be unrelated to your connection string.

>> First-chance exception at 0x7c81eb33 in Book.exe: Microsoft C++ exception: _com_error at memory location 0x0013fba4.

Try running your application with a debugger attached and breaking at the point the exception occurs. This will likely give you more insight into the cause of the problem.

Hope this helps,
Vaughn

how can i connect to sqlserver2005 express by ado

hr = m_pConnection.CreateInstance("ADODB.Connection");
if (SUCCEEDED(hr))
{
if (FAILED(m_pConnection->Open("Provider = sqloledb;Server=(local);Database=c863;Trusted_Connection=yes","","",-1)))
{
AfxMessageBox("Can not open Database!");
m_pConnection.Release();
return FALSE;
}

}
when i debug ,there is an exception at "m_pConnection->Open("Provider = sqloledb;Server=(local);Database=c863;Trusted_Connection=yes","","",-1)))"
the exception is
'Book.exe': Loaded 'C:\Program Files\Common Files\System\Ole DB\sqloledb.rll', Binary was not built with debug information.
First-chance exception at 0x7c81eb33 in Book.exe: Microsoft C++ exception: _com_error at memory location 0x0013fba4..
how should i do?Try

Server=(local)\SQLEXPRESS

SQL Express is installed as a "named" instance by default, an drequires the instance name specification when making a connection (as opposed to a "default" instance).|||Sorry,it dont still work.the exception is
"First-chance exception at 0x7c81eb33 in Book.exe: Microsoft C++ exception: _com_error at memory location 0x0013fba4.."
|||It looks like the failure may be unrelated to your connection string.

>> First-chance exception at 0x7c81eb33 in Book.exe: Microsoft C++ exception: _com_error at memory location 0x0013fba4.

Try running your application with a debugger attached and breaking at the point the exception occurs. This will likely give you more insight into the cause of the problem.

Hope this helps,
Vaughnsql

Friday, March 23, 2012

How can I avoid that the OLEDB Provider intercepts the error?

I have an stored procedure which is called by using ADO and OLEDB. I wish that when an error occurs (such as when a contraint is violated or trying to insert NULL in a not-null column) the error message is stored on an output parameter and returned to the client, without the error being raised by the OLEDB Provider.

How can I do that?

Thanks a lot in advance.For it is a lot of ways... true way and another ones...
Check inserted(input) data before ... insert update delete through sp... Using "INSTEAD OF
" triggers for checking yours data... client side errors handling ... ADO have got Errors collection...

http://msdn.microsoft.com/
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/trblsql/tr_errorformats_0tpv.asp

MSDN
Handling Errors in Visual C++
In COM, most operations return an HRESULT return code that indicates whether a function completed successfully. The #import directive generates wrapper code around each "raw" method or property and checks the returned HRESULT. If the HRESULT indicates failure, the wrapper code throws a COM error by calling _com_issue_errorex() with the HRESULT return code as an argument. COM error objects can be caught in a try-catch block. (For efficiency's sake, catch a reference to a _com_error object.)
Remember, these are ADO errors: they result from the ADO operation failing. Errors returned by the underlying provider appear as Error objects in the Connection object's Errors collection.
The #import directive only creates error-handling routines for methods and properties declared in the ADO .dll. However, you can take advantage of this same error-handling mechanism by writing your own error-checking macro or inline function. See the topic Visual C++ Extensions for examples.

MSDN
How Does ADO Report Errors?
ADO notifies you about errors in several ways:
ADO errors generate a run-time error. Handle an ADO error the same way you would any other run-time error, such as using an On Error statement in Visual Basic.
Your program can receive errors from OLE DB. An OLE DB error generates a run-time error as well.
If the error is specific to your data provider, one or more Error objects are placed in the Errors collection of the Connection object that was used to access the data store when the error occurred.
If the process that raised an event also produced an error, error information is placed in an Error object and passed as a parameter to the event. See Chapter 7: Handling ADO Events <pg_ado_eventhandling.htm> for more information about events.
Problems that occur when processing batch updates or other bulk operations involving a Recordset can be indicated by the Status property of the Recordset. For example, schema constraint violations or insufficient permissions can be specified by RecordStatusEnum values.
Problems that occur involving a particular Field in the current record are also indicated by the Status property of each Field in the Fields collection of the Record or Recordset. For example, updates that could not be completed or incompatible data types can be specified by FieldStatusEnum values.

Monday, March 19, 2012

How can I access data to SQL server 2005 using Windows application,ADO.net and .Net remoting.

How can I access data to SQL server 2005 using Windows form application,ADO.net and .Net remoting?

Can anybody help me? please...

This question is too vague. Do you have a specific issue or question?|||

Here is one place to start:

http://www.411asp.net/home/tutorial/howto/applicat

I suggest that you go to your local bookstore or library and look over the options. Or Google?

"create .NET application"

|||

Deepak Kapoor wrote:

This question is too vague. Do you have a specific issue or question?

Hi ! Deepak Kapoor

I am a C# beginner, I have to write some code using windows application,that's need to INSERT,UPDATE,SELECT and DELETE data to sql server using ADO.net and .net remoting...

1.The client application include 1 dataGridView and 4 buttons(Add,Delete,Edit and Load).

2.The server application include 1label and 1 button to start server application.

3.The remote object.

Here are my questions. Big Smile

I already wrote for the Load button of the client application.But, I dont know how to program for the remaining buttons.And I want to access data directly into the dataGridView.If you know how to do,please post some explaination and give me some example code.

This is my remote object.

public class AuthorList : MarshalByRefObject

{

private static string connectionString = @."server = BMSTU\KTS ;database = kts;uid=sa;pwd=";

public DataTable GetAuthors()

{

string SQL = "SELECT * FROM Author";

// Create ADO.NET objects to execute the DB query.

SqlConnection conn = new SqlConnection(connectionString);

SqlCommand cmd = new SqlCommand(SQL, conn);

SqlDataAdapter adapter = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();

// Execute the command.

try

{

conn.Open();

adapter.Fill(ds, "Author");

}

catch (Exception err)

{

Console.WriteLine(err.ToString());

}

finally

{

conn.Close();

}

// Return the first DataTable in the DataSet to the caller.

return ds.Tables["Author"];


}

// This method allows you to verify that the object is running remotely.

public string GetHostLocation()

{

return AppDomain.CurrentDomain.FriendlyName;

}

}

This is the Server application.

private void button1_Click(object sender, EventArgs e)

{

HttpChannel myChannel = new HttpChannel(8080);

ChannelServices.RegisterChannel(myChannel);

RemotingConfiguration.RegisterWellKnownServiceType(typeof(BookServer.AuthorList),

"AuthorList", WellKnownObjectMode.Singleton);

label1.Text = "Server Started";

button1.Enabled = false;

}

This is the Client application

private void btnLoad_Click(object sender, EventArgs e)

{

AuthorList atlst = (AuthorList)Activator.GetObject(typeof(AuthorList),

"http://localhost:8080/AuthorList", WellKnownObjectMode.Singleton);

dataGridView2.DataSource = null;

dataGridView2.DataSource = atlst.GetAuthors();

}

If you know how to program for the btnAdd,btnEdit and btnDelete of the Client application.And how to program in server and remote object.I am hoping anybody's help.

Best regards ,

thanks,

WhoAmI?

|||hmmm, can anyone help me?