Friday, February 17, 2012

Create Database problem.

Hello,
I am having problems creating a database and immediately filling it
with data. I have a sql script which i can run against a database and i
have a sql query (create database <name> ) which i run first.
My problem is that when i login to the new database i get a login
failed. If i try again (or wait a while between the "create database"
statement) and the runsqlscript function it's works OK. So it seems
that when i run "create database" the database is not completely
created when the code returns.
My psuedo code (run from c#)
//the sql script
StreamReader sr = new StreamReader(@."D:\uda.sql");
string connstr =
" server=cm041w;database=testsql;trusted_c
onnection=yes";
if (!SqlManager.Exists(connstr))
SqlManager.CreateDB" server=localhost;database=master;trusted
_connection=yes"
,"testsql");
SqlManager.RunSQLScriptOnDb(connstr,sr);//run the script against the
new dB
Internally my SqlManager uses normal T-sql queries which i can show if
necessary. Can someone explain why i need to wait between the createDB
and RunSqlScript methods'
Thanks,
Martijn
Groningen NetherlandsHave you run sp_grantdbaccess to grand db access to the login?
<mmuurman@.gmail.com> wrote in message
news:1147160273.460752.67020@.i40g2000cwc.googlegroups.com...
> Hello,
> I am having problems creating a database and immediately filling it
> with data. I have a sql script which i can run against a database and i
> have a sql query (create database <name> ) which i run first.
> My problem is that when i login to the new database i get a login
> failed. If i try again (or wait a while between the "create database"
> statement) and the runsqlscript function it's works OK. So it seems
> that when i run "create database" the database is not completely
> created when the code returns.
> My psuedo code (run from c#)
> //the sql script
> StreamReader sr = new StreamReader(@."D:\uda.sql");
> string connstr =
> " server=cm041w;database=testsql;trusted_c
onnection=yes";
> if (!SqlManager.Exists(connstr))
> SqlManager.CreateDB" server=localhost;database=master;trusted
_connection=ye
s","testsql");
> SqlManager.RunSQLScriptOnDb(connstr,sr);//run the script against the
> new dB
> Internally my SqlManager uses normal T-sql queries which i can show if
> necessary. Can someone explain why i need to wait between the createDB
> and RunSqlScript methods'
> Thanks,
> Martijn
> Groningen Netherlands
>|||when i do that i also get an error of login failed. Allthough the user
i am working in is a dbo. If i wait a while the login is automatically
created...

No comments:

Post a Comment