|
sp_attach_db is a system stored procedure that is in the SQL Server master database.
If you really don't want to use it, you can use what is below (which is all the sp_attach_db does).
Also, I put this in vb.net - the last thing I posted was C#.
Imports System.Data
Imports System.Data.SqlClient
Dim conn As New SqlConnection
Dim myCommand As SqlCommand
conn.ConnectionString = "Data Source=(local);Initial Catalog=master;Integrated Security=SSPI"
conn.Open()
myCommand = conn.CreateCommand()
myCommand.CommandText = "CREATE DATABASE [ATestDB] ON (FILENAME = 'C:\TestPath\ATestDB_Data.MDF'), (FILENAME = 'C:\TestPath\ATestDB_Log.LDF') FOR ATTACH"
myCommand.ExecuteScalar()
Just change the name of ATestDB to whatever yours is, and the paths and filenames too.
----------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
-- modified at 13:55 Thursday 1st June, 2006
|
|
|
|
|
Hi , thank you very very much this last one worked thank you i don't know without you what i would do thnx again
now if you permit i want to ask you some other things abt this
well , first when i create this database with the way you told me it work
but now if i already have the database attached i have to change ma code to :
conn.ConnectionString = "Data Source=(local);InitialCatalog=MyDataBase;Integrated Security=SSPI"
& i have to delete this 4 lines from code :
conn.Open()myCommand = conn.CreateCommand()myCommand.CommandText = "CREATE DATABASE [ATestDB] ON (FILENAME = 'C:\TestPath\ATestDB_Data.MDF'), (FILENAME = 'C:\TestPath\ATestDB_Log.LDF') FOR ATTACH"myCommand.ExecuteScalar()
like this i will just extract records from the database this is first
second thing i want to detect the name of the server automatically
like this :
conn.ConnectionString = "Data Source= <big>Here i have to write the name of the server but i don't know what is it name so how can i know without asking the user ?? </big>;InitialCatalog=MyDataBase;Integrated Security=SSPI" thank you very much for help
try to be good if you can't be the best
|
|
|
|
|
(local) will work if the server is on the local machine (the same machine the application is running on).
If it isn't local, there might be numerous instances of SQL Server running on the user's network. If you don't know the name of their server, how would you know which one to connect to without asking the user? You could present them with a dialog box that allows them to choose one of those available, then save what they chose somewhere (registry, file, whatever) so you don't have to ask them again. Or, make this a part of your installation process. There are various ways of handling this issue.
----------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
hi
I need to know how can I code and decode password in Sql server 2005
(secure)
Thanks
dadax
|
|
|
|
|
Hi dadax!
Check my blog article at http://www.cubido.at/Blog/tabid/176/EntryID/34/Default.aspx. It describes how to do that using SQL Server's new encryption/decryption feature.
Regards,
Rainer.
Rainer Stropek
cubido business solutions gmbh
Email r.stropek@cubido.at
Visit my blog at http://www.cubido.at/Blog/tabid/176/BlogID/4/Default.aspx
|
|
|
|
|
Can the Oralce ODP.Net driver be used with Reporting Services 2000? If so, how do you set up the connection? Thanks.
|
|
|
|
|
Hi buddies i have a relativly simple question
i whant to exececute a select statment in c++
but for the WHERE part of the statment i want to read it from a variable of type string
Let me be more precise.
string token;
token="SomeName"
pCommand->CommandText = "SELECT * FROM Table1 WHERE Name=?";//WHERE Name=token
Any ideas pls help
Thanks again
|
|
|
|
|
Like this
pCommand->CommandText = "SELECT * FROM Table1 WHERE Name='"
& token & "'" ;//WHERE Name=token
|
|
|
|
|
string strsql;
sprintf(strsql, "SELECT * FROM Table1 WHERE Name='%s'", token);
pCommand->CommandText =strsql;
|
|
|
|
|
Hello,
I m new to vb.net. I dont know how to connect the Radiobutton with Datasource.
Can anybody help me with example
Regards
Preetha
|
|
|
|
|
.net 2.0 or 1.1?
For basic code behind binding, you need a datareader, or dataset and then set
myRadio.DataSource = myDataSource
myRadio.DataTextField = "TextFieldInSource"
myRadio.DataValueField = "ValueFieldInSource"
myRadio.DataBind()
|
|
|
|
|
|
configuration:
server:
MySql 5.0.15-nt via tcp/ip
Client:
MySql Client Version 5.0.11
Operating system:
XP
Startup Variables:
Max Packet Size 1mb
Net Buffer Length 16k
I am using Inodb and the c/c++ api
Let me know if you need additional config info.
OK.
I have an app which scans documents and then stores them as a blob. The typical size of an image is around 22k.
During storage, the app batches about 100 of these images along with other information in structures in memory and then initiates a transaction and stores all 100, committing when finished.
This works as expected and the time to do this commit is a couple of seconds, anyway, it is fast enough that it is not an issue.
My problem is this:
When I go to retrieve a single image, it can take as long as 60 seconds. I've played around with this quite a lot and when monitoring the network, to see when the image is downloaded, the image appears to come down right away and then the statement hangs/waits for a timeout before returning... as long as 60 seconds.
The statement which hangs is the:
imageRes_set = mysql_store_result(m_mysqlConn);
QStr.Format("select Image from docimages where BatchNum = %s and ItemId = %s and Side = \"%c\"", BatchNum, ItemId, 'F');
mysql_query(m_mysqlConn, LPCSTR(QStr));
int ret = mysql_errno(m_mysqlConn);
if (mysql_errno(m_mysqlConn) != 0) {
str.Format("Error doing Preset Query 51 - %s\nFailure to do Select on Image", mysql_error(m_mysqlConn));
AfxMessageBox(str);
Close_Database_Connection();
return(false);
}
imageRes_set = mysql_store_result(m_mysqlConn);
row = mysql_fetch_row(imageRes_set);
if (row == NULL) {
Mess1.Format("************ The Image, in batch num (%s) does not exist in the Data Base ************\n\n ", BatchNum);
Mess2 = "\tIt is not possible to View and Key an non existing Image\n";
AfxMessageBox (Mess1 + Mess2, MB_OK | MB_APPLMODAL | MB_ICONQUESTION, 0 );
Close_Database_Connection();
return(false);
}
-- modified at 23:19 Tuesday 30th May, 2006
|
|
|
|
|
|
Have you considered mysql_use_result() rather than mysql_store_result() ?
DOCUMENTATION
There are two ways for a client to process result sets. One way is to retrieve the entire result set all at once by calling mysql_store_result(). This function acquires from the server all the rows returned by the query and stores them in the client. The second way is for the client to initiate a row-by-row result set retrieval by calling mysql_use_result(). This function initializes the retrieval, but does not actually get any rows from the server.
In both cases, you access rows by calling mysql_fetch_row(). With mysql_store_result(), mysql_fetch_row() accesses rows that have already been fetched from the server. With mysql_use_result(), mysql_fetch_row() actually retrieves the row from the server. Information about the size of the data in each row is available by calling mysql_fetch_lengths().
After you are done with a result set, call mysql_free_result() to free the memory used for it.
The two retrieval mechanisms are complementary. Client programs should choose the approach that is most appropriate for their requirements. In practice, clients tend to use mysql_store_result() more commonly.
An advantage of mysql_store_result() is that because the rows have all been fetched to the client, you not only can access rows sequentially, you can move back and forth in the result set using mysql_data_seek() or mysql_row_seek() to change the current row position within the result set. You can also find out how many rows there are by calling mysql_num_rows(). On the other hand, the memory requirements for mysql_store_result() may be very high for large result sets and you are more likely to encounter out-of-memory conditions.
An advantage of mysql_use_result() is that the client requires less memory for the result set because it maintains only one row at a time (and because there is less allocation overhead, mysql_use_result() can be faster). Disadvantages are that you must process each row quickly to avoid tying up the server, you don't have random access to rows within the result set (you can only access rows sequentially), and you don't know how many rows are in the result set until you have retrieved them all. Furthermore, you must retrieve all the rows even if you determine in mid-retrieval that you've found the information you were looking for.
----------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Thanks for the response Eric...
Yes, I have tried both mysql_use_result() and mysql_store_result() with the same outcome, it hangs for about 60 seconds.
I have also checked the rows and fields and when it does return (correctly by the way and with the image) there is exactly 1 field and 1 row as would be expected.
Anything you think I might try or look at?
|
|
|
|
|
Try disabling your virus scanning software.
----------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Good idea.
I used enditall to close most of the apps on the client side.
I disabled Norton on the client and server side.
Tried again and had the same result... 60 seconds
|
|
|
|
|
You got me on this one.
Could try returning more than one row (just to see how it works - slower, faster, just the same?)...
or, try starting mysql with the --quick switch.
Maybe run your app on a clean OS install.
I'm just grasping at straws - as I'm sure you have done yourself.
Sorry, I can't help.
----------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Is there something I'm missing on the setup of the server??
Anyone any ideas?
|
|
|
|
|
Hi again
I'm trying to connect to an access db using ADO
i use some sample codes to perform a simple SELECT query and display them through a recordset. I've tryed really hard to make it work i've searched everywhere pls help me find the problem.
This is the code i use::
<br />
<br />
<br />
#include <br />
#include <br />
#include <br />
<br />
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \<br />
no_namespace rename("EOF", "EndOfFile")<br />
<br />
void main(int argc, char* argv[])<br />
{<br />
<br />
HRESULT hr = S_OK;<br />
_ConnectionPtr m_pConn;<br />
try<br />
{<br />
HRESULT hr = m_pConn.CreateInstance(__uuidof(Connection));<br />
if (FAILED( hr ))<br />
cout<<"Can't create an intance of ADO.Connection"<<endl;<br />
<br />
if (FAILED( m_pConn->Open(_bstr_t("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =ADOTestDB.MDB"),<br />
_bstr_t( "" ),<br />
_bstr_t( "" ), <br />
adModeUnknown )))<br />
<br />
cout<<"Can't open datasource"<<endl;<br />
<br />
<br />
_CommandPtr pCommand;<br />
pCommand.CreateInstance (__uuidof (Command));<br />
pCommand->ActiveConnection = m_pConn; <br />
pCommand->CommandText = "Select Name,Dept From Student";<br />
_RecordsetPtr pRecordset;<br />
pRecordset.CreateInstance (__uuidof (Recordset));<br />
pRecordset->CursorLocation = adUseClient;<br />
pRecordset->Open ( (IDispatch *) pCommand, vtMissing, adOpenStatic,<br />
adLockBatchOptimistic, adCmdUnknown);<br />
<br />
_bstr_t valField1;<br />
int valField2;<br />
pRecordset->MoveFirst();<br />
if (!pRecordset->EndOfFile)<br />
{<br />
while(!pRecordset->EndOfFile)<br />
{<br />
valField1 = pRecordset->Fields->GetItem("Name")->Value;<br />
valField2 = pRecordset->Fields->GetItem("Dept")->Value.intVal;<br />
printf("%d - %s\n",valField2,(LPCSTR)valField1);<br />
pRecordset->MoveNext();<br />
}<br />
}<br />
<br />
<br />
}catch( _com_error &ce )<br />
{<br />
printf("Error:%s\n",ce.Description);<br />
<br />
}<br />
m_pConn->Close();<br />
<br />
}<br />
i get an exeption
"Can't create an intance of ADO.Connection"
and the i asks if i want to debug
Pls help me i'm trying a lot to connect to a db and enything i do seems to be wrong
and the truth is that everytime i post a msg about C++ and ADO no one
replies.
pls i'm desparate
|
|
|
|
|
|
Hello Dear,
Please give me some good ADO Books name.
N.Rajakumar B.E.,
Application Developer,
www.newdreamz.tk
|
|
|
|
|
Hi ppl,
I have installed Server 2005 and when I try to run my application I get the following error mssg:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.
Code:
Imports System.Data
Imports System.Data.SqlClient
Public Conn As SqlConnection = New SqlConnection
Dim da As New SqlDataAdapter
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Conn.ConnectionString = "Data Source=(local);" & _
"Initial Catalog=Rsch1;" & _
"Integrated Security=SSPI"
Conn.Open() ----------> Error Mssg
What could be the problem?
Tnx
|
|
|
|
|
try adding:
Imports System.Data.Sql
“Profanity is the attempt of a lazy and feeble mind to express itself forcefully”
|
|
|
|